#4278 closed defect (invalid)
32 bit OMC treats Reals as Integers and truncates them
Reported by: | Owned by: | somebody | |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | *unknown* | Version: | |
Keywords: | Cc: |
Description
The following leads to a warning and possibly error in 32bit OpenModelica:
constant Modelica.SIunits.Time timeStampsNewYear = 1262304000;
Time is a Real, but it gets treated as Integer and then it is truncated with following error message:
OpenModelica only supports 31-bit signed integers! Truncating integer: 1262304000 to 1073741823
To fix it, I used 1262304000.0 instead. Is that a bug in OpenModelica?
https://github.com/iea-annex60/modelica-annex60/issues/668
https://github.com/iea-annex60/modelica-annex60/pull/669
Change History (5)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
This is not a bug.
The grammar clearly says that a literal number is a Real if you have a dot or the scientific notation:
UNSIGNED_INTEGER = DIGIT { DIGIT } UNSIGNED_NUMBER = UNSIGNED_INTEGER [ "." [ UNSIGNED_INTEGER ] ] [ ( "e" | "E" ) [ "+" | "-" ] UNSIGNED_INTEGER ]
We give this warning to tell you that the integer number you used is more than an integer can hold. Is way better than just truncating the number to the max integer we support.
comment:3 by , 8 years ago
So using
Real xyz=3600000000;
is wrong and I should always use
Real xyz=3600000000.0;
Sorry if the grammar is not clear to me. To me it was surprising that I had to use the second way to really make it a Real, but if that is how it is intended that is also fine and now I know, thanks to the error message and to you.
comment:4 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Took me a while, but I think I now finally understood your answer. The warning refers to the literal, not to the variable.
comment:5 by , 8 years ago
One more comment: I showed two cases, one time the Integer was truncated and the other time it was converted into a Real. Wouldn't it be better to always convert to Real instead of truncating?
Is conversion Integer->Real safe, is a warning required, or can it be done silently, always?
Related: This code:
produces this warning:
Again, the fix is to use 3600000000.0