curiousdannii-testing / inform7-imported-bugs

0 stars 0 forks source link

[I7-2038] [Mantis 2075] multiplying a multi-part unit by a real number yields absurd results #46

Closed curiousdannii-testing closed 2 years ago

curiousdannii-testing commented 2 years ago

Reported by : mattweiner

Description :

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.

Steps to reproduce :

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]."

Additional information :

Output: Number result: $7.00. Real number result: $11439308.80.

Possibly related to http://inform7.com/mantis/view.php?id=1935.

Forum thread: https://www.intfiction.org/forum/viewtopic.php?f=7&t=26554&p=143414#p143414.

imported from: [Mantis 2075] multiplying a multi-part unit by a real number yields absurd results
  • status: Closed
  • resolution: Resolved
  • resolved: 2022-04-10T04:20:50+10:00
  • imported: 2022/01/10
curiousdannii-testing commented 2 years ago

557058:4c095ffd-6d6f-47ce-9e73-77c613347b86:

Comment by zarf :
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).

curiousdannii-testing commented 2 years ago

61eedb62875fc10070240916:

Fixed via this commit: https://github.com/ganelson/inform/commit/389d13d86b2ba904702df11985d47c2d6c066311