Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 bit integer overflow in CalendarTime #668

Closed
Mathadon opened this issue Feb 13, 2017 · 5 comments · Fixed by #669
Closed

32 bit integer overflow in CalendarTime #668

Mathadon opened this issue Feb 13, 2017 · 5 comments · Fixed by #669

Comments

@Mathadon
Copy link
Member

Mathadon commented Feb 13, 2017

@tatigabd reports in open-ideas/IDEAS#669 (comment) that OpenModelica (32 bit version) generates warnings when trying to use IDEAS.

[33] 11:01:03 Syntax Warning
[C:/OpenModelica1.9.7/lib/omlibrary/IDEAS-master/IDEAS/Buildings/Validation/BESTEST.mo: 15:25-15:35]: Modelica only supports 32-bit signed integers! Transforming: 3600000000 into a real

[34] 11:01:03 Syntax Warning
[C:/OpenModelica1.9.7/lib/omlibrary/IDEAS-master/IDEAS/Utilities/Time/CalendarTime.mo: 43:5-43:15]: OpenModelica only supports 31-bit signed integers! Truncating integer: 1262304000 to 1073741823

This is probably caused by unix time stamps overflowing 31 bit signed integer because 2^30 = 1073741824 > 1.5e9. We could avoid this by using a Real instead, or advice users to use the 64 bit version, which does work.

@thorade
Copy link
Member

thorade commented Feb 15, 2017

It probably is the same warning with omc 1.11?
Note for myself: to quickly check the omc bitness on Linux, run
which omc | xargs file
or
file $(which omc)

@mwetter
Copy link
Contributor

mwetter commented Feb 15, 2017

We should change the code so it works on 32 bit as some users may not have the option to generate 64 bit.

@Mathadon
Copy link
Member Author

We are already using Reals for representing epochs:

  constant Real timeStampsNewYear[12] = {
    1262304000, 1293840000, 1325376000,
    1356998400, 1388534400, 1420070400,
    1451606400, 1483228800, 1514764800,
    1546300800, 1577836800, 1609459200}
    "Epoch time stamps for new years day 2010 to 2021";

Possibly expressions such as rem(unixTimeStamp,3600*24) get translated internally to an expression that requires integers.

Also I can't reproduce the problem since I'm not sure how to launch the 32 bit version of OM? Do you need to install it separately?

We could check with OM if they can identify what equation causes the error?

@thorade
Copy link
Member

thorade commented Feb 16, 2017

Looks like it is not easily possible to have 32 and 64 bit OMC in parallel on Linux:
https://openmodelica.org/forum/default-topic/2115-32bit-and-64bit-in-parallel

So I installed OpeneModelica 1.11 32bit on my Windows 10 and it was sufficient to just open the Annex60 library to reproduce the warning.
Modelica.SIunit.Time is already a Real, but OpenModelica somehow thinks it is an Integer, this might be a bug in OpenModelica!?
Using the same numbers with .0 attached, tricks OpenModelica into treating them as real Reals and I am able to open the Annex60 library without warning and simulate the Utilities.Time.Examples and Validation (before, the Validation did not simulate).

@thorade
Copy link
Member

thorade commented Feb 20, 2017

I also opened a ticket in the OpenModelica tracker:
https://trac.openmodelica.org/OpenModelica/ticket/4278

EDIT: This is the intended behavior, it seems:
https://trac.openmodelica.org/OpenModelica/wiki/WritingCompliantLibraries#LargeIntegervalues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants