Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4713 closed defect (invalid)

literal double value output by omc exceeds DBL_MAX

Reported by: john.pye@… Owned by: lochel
Priority: normal Milestone:
Component: Third-Party Libraries Version: v1.13.0-dev-nightly
Keywords: compiler, omc Cc: ali.shirazi@…

Description

Hi there

While using omc from the Nightly builds, OpenModelica 1.13.0~dev-536-g587d18b, as well as with previous version 1.12, we receive compiler warnings as follows:

SimpleSystem.c:1160:90: warning: magnitude of floating-point constant too large

for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]

.../* pri.nextTimeEventScaled DISCRETE */,1.797693134862316e+308);


SimpleSystem.c:1161:152: warning: magnitude of floating-point constant too large

for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]

.../* pri.nextTimeEventScaled DISCRETE */:1.797693134862316e+308);


The function that is causing this problem in the OMC C-code output is:

/*

equation index: 150
type: WHEN


when {$whenCondition1} then

pri._nextTimeEvent = if pri.nextTimeEventScaled < 1.797693134862316e+308 then pri.nextTimeEventScaled else 1.797693134862316e+308;

end when;
*/

void SimpleSystem_eqFunction_150(DATA *data, threadData_t *threadData)
{

TRACE_PUSH
const int equationIndexes[2] = {1,150};
modelica_boolean tmp29;
if((data->localData[0]->booleanVars[0] /* $whenCondition1 DISCRETE */ && !data->simulationInfo->booleanVarsPre[0] /* $whenCondition1 DISCRETE */ /* edge */))
{

tmp29 = Less(data->localData[0]->realVars[70] /* pri.nextTimeEventScaled DISCRETE */,1.797693134862316e+308);
data->localData[0]->realVars[69] /* pri.nextTimeEvent DISCRETE */ = (tmp29?data->localData[0]->realVars[70] /* pri.nextTimeEventScaled DISCRETE */:1.797693134862316e+308);

}
TRACE_POP

}

On close inspection, you can see that the literal double value in the code is slightly rounded up from DBL_MAX.

I think the best solution here would be for the C code from Modelica to output either the macro 'DBL_MAX' or else a value that is safely less than DBL_MAX eg half its value.

Cheers
JP

PS if more details are needed, you can reproduce this bug directly following the instructions at https://github.com/SolarTherm/SolarTherm/wiki/Building-SolarTherm.

Change History (5)

comment:1 Changed 7 years ago by john.pye@…

Further to this, we found that by adjusting the value of DBL_MAX, which is hard-wired into the code of /usr/lib/omlibrary/Modelica 3.2.2/Blocks/Sources.mo (line 2288) "const Real DBL_MAX = 1.79....e+308", we were able to make the compiler warning go away. We rounded the last decimal in the mantissa down to 0.

Hope that helps!

comment:2 Changed 7 years ago by john.pye@…

  • Summary changed from literal doulbe value output by omc exceeds DBL_MAX to literal double value output by omc exceeds DBL_MAX

comment:3 Changed 7 years ago by sjoelund.se

  • Component changed from Code Generation to Third-Party Libraries
  • Milestone Future deleted
  • Resolution set to invalid
  • Status changed from new to closed

The MSL code is probably wrong and should ideally use Constants.inf (and if that is too small, ModelicaServices.Machine.inf should be increased). MSL issues go to: https://github.com/modelica/Modelica/issues/new

From OpenModelica's point of view, perhaps we could tweak the value to be output such that GCC doesn't give warnings, but the code still runs fine, right?

comment:5 Changed 7 years ago by john.pye@…

Another option would be to explicitly suppress this particular warning from GCC... but only if we can be sure it won't cause issues else where. One question I had was what value GCC casts this overflowing DBL_MAX to? No risk of overflow, is there?

I don't know how you can tweak the value without changing the Modelica Sources.mo file...?

Note: See TracTickets for help on using tickets.