Opened 7 years ago

Closed 7 years ago

#4385 closed defect (invalid)

Operator ^ fails, depending on the used data types

Reported by: jens.schoenbohm@… Owned by: sjoelund.se
Priority: normal Milestone:
Component: Frontend Version:
Keywords: exponentiation Cc:

Description

The exponentiation operator fails in some cases, as one can see below.

function main	
  protected
	Integer a[:];
	Integer b[:];
	Real c[:];
        Real d[:];
  algorithm
		a := {i^2 for i in {1, 3, 6, 7, 8}}; // Error: Kann Typ des Ausdrucks i ^ 2 nicht aufl▒sen. Operanden haben Typen #Integer, Integer in Komponente <NO COMPONENT>.
		b := {i^2 for i in 1:2:5}; // Error: Type mismatch in assignment in b := {1.0, 9.0, 25.0} of Integer[:] := Real[3]
		c := {i^2 for i in {1.0, 3.0, 6.0, 7.0, 8.0}}; // OK
                d := {i^2 for i in {1, 3, 6, 7, 8}}; // Error: Kann Typ des Ausdrucks i ^ 2 nicht aufl▒sen. Operanden haben Typen #Integer, Integer in Komponente <NO COMPONENT>.
end main;

Change History (3)

comment:1 Changed 7 years ago by hkiel

  • Component changed from MetaModelica to Frontend
  • Owner changed from sjoelund.se to somebody

I looked into the FrontEnd and it seems i and 2 in i^2 are both handled as real numbers instead of integers.
At least I see the call to ValuesUtil.safeIntRealOp() where two real numbers are passed in.

Also, when using setCommandLineOptions("-d=noevalfunc"); the code works as expected without any warning or error.

comment:2 Changed 7 years ago by hkiel

  • Owner changed from somebody to sjoelund.se
  • Status changed from new to assigned

comment:3 Changed 7 years ago by perost

  • Resolution set to invalid
  • Status changed from assigned to closed

The Modelica specification says (10.6.7):

Exponentiation "a^b" is defined as pow(double a,double b) in the ANSI C library if both "a" and "b" are Real scalars. A Real scalar value is returned. If "a" or "b" are Integer scalars, they are automatically promoted to "Real".

So the only thing not working correctly in your example would be getting an error on the last assignment to d, but that's working fine for me. I will therefore close this ticket, but please reopen it if you can reproduce that particular issue in the latest version of OpenModelica.

Note: See TracTickets for help on using tickets.