MantisBT - Core Inform
View Issue Details
0002075Core InformEquations, units, arithmeticpublic2018-09-09 18:042018-09-10 20:48
OS XEl Capitan10.11.6
(serious/mild) Game compiles but misbehaves
0002075: multiplying a multi-part unit by a real number yields absurd results
When multiplying a multi-part unit, such as $1.99 specifying a cash-value, by a real number, such as 1.0, the result is some sort of integer overflow.
Lab is a room.

Cash-value is a kind of value. $1.99 specifies a cash-value.

Holdings is a cash-value that varies. Holdings is $3.50.

When play begins: say "Number result: [2 times holdings]. Real number result: [2.0 times holdings]."
Output: Number result: $7.00. Real number result: $11439308.80.

Possibly related to [^]

Forum thread: [^]

No tags attached.
Issue History
2018-09-09 18:04mattweinerNew Issue
2018-09-10 20:48zarfNote Added: 0004807
2018-09-10 20:48zarfStatusnew => confirmed

2018-09-10 20:48   
I think this is not related to 1935, after all. The generated code is

     tmp_0 = (REAL_NUMBER_TY_Times(1073741824, NUMBER_TY_to_REAL_NUMBER_TY((Global_Vars-->10))));

That is, it's converting the scaled value (pennies) to a real number, correctly multiplying that by 2.0 (using real multiplication), but then treating the resulting value as a scaled value again. It's missing the step where it converts the real back to an integer (pennies again).