Opened 8 years ago
Closed 7 years ago
#4385 closed defect (invalid)
Operator ^ fails, depending on the used data types
Reported by: | Owned by: | Martin Sjölund | |
---|---|---|---|
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 by , 8 years ago
Component: | MetaModelica → Frontend |
---|---|
Owner: | changed from | to
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → 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.
I looked into the FrontEnd and it seems
i
and2
ini^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.