Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#4278 closed defect (invalid)

32 bit OMC treats Reals as Integers and truncates them

Reported by: m.thorade@… 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 Changed 8 years ago by m.thorade@…

Related: This code:

constant Real MWh = 1/3600000000;

produces this warning:

Modelica only supports 32-bit signed integers! Transforming: 3600000000 into a real

Again, the fix is to use 3600000000.0

comment:2 Changed 8 years ago by adrpo

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 Changed 8 years ago by m.thorade@…

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 Changed 8 years ago by m.thorade@…

  • Resolution set to invalid
  • Status changed from new to 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 Changed 8 years ago by m.thorade@…

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?

Note: See TracTickets for help on using tickets.