Page 1 of 1

[0.16.36] Rounding error with modules?

Posted: Tue May 01, 2018 6:13 pm
by uukgoblin
Hi,

I wanted to point out an assembler 3 with 2x speed3 modules is showing up energy consumption of 504 kW (correctly), but as soon as you add a 3rd speed3 module (or more), it seems to lose a kW.

With 3x speed3 it should be using 210 * (1 + 3 * 70%) = 651 kW, but the info box (shown when you hover mouse over the building) shows only 650 kW. With 4 modules, it should be 798 kW, but shows only 797.

Is it just a display issue, or is it actually taking the wrong amount of power?

It's quite peculiar as there should be no fractions or rounding going on there anywhere - the result is an exact number, and one module increases power usage by exactly 147 kW (no fractions or rounding either). Even if you divide 210 by 7 or 70 incorrectly first (to later multiply it by 10 or 100, which you should have done as the first step), you still end up with no fractions on the way.

Re: [0.16.36] Rounding error with modules?

Posted: Tue May 01, 2018 8:47 pm
by uukgoblin
What's more bizarre, is that the game is perfectly capable of displaying fractions there, BUT DISPLAYS THEM WRONG! For instance if you max out Efficiency modules to get the -80% energy bonus, the game shows "41.9 kW", instead of 210 * 20% = 42!

This particular example smells like it's trying to avoid the answer to the ultimate question of life, the universe, and everything?

Re: [0.16.36] Rounding error with modules?

Posted: Tue May 01, 2018 10:37 pm
by kitcat
This is most likely a result of imperfect representation of real numbers. 80 % is 0.8, which cannot be represented in binary and becomes 0.80000001192092895508 when forced into a float type variable.
1 - 0.80000001192092895508 = 0.19999998808
210 * 0.19999998808 = 41.9999974968
Truncate the fractional part to one digit and you get 41.9.

Maybe the game isn’t rounding that properly? It should obviously be rounded up to 42.

Re: [0.16.36] Rounding error with modules?

Posted: Wed May 02, 2018 7:23 am
by Rseding91
kitcat wrote:This is most likely a result of imperfect representation of real numbers. 80 % is 0.8, which cannot be represented in binary and becomes 0.80000001192092895508 when forced into a float type variable.
1 - 0.80000001192092895508 = 0.19999998808
210 * 0.19999998808 = 41.9999974968
Truncate the fractional part to one digit and you get 41.9.

Maybe the game isn’t rounding that properly? It should obviously be rounded up to 42.
The game doesn't round numbers.

Re: [0.16.36] Rounding error with modules?

Posted: Wed May 02, 2018 7:38 am
by Dominik
Rseding91 wrote:
kitcat wrote:This is most likely a result of imperfect representation of real numbers. 80 % is 0.8, which cannot be represented in binary and becomes 0.80000001192092895508 when forced into a float type variable.
1 - 0.80000001192092895508 = 0.19999998808
210 * 0.19999998808 = 41.9999974968
Truncate the fractional part to one digit and you get 41.9.

Maybe the game isn’t rounding that properly? It should obviously be rounded up to 42.
The game doesn't round numbers.
U sure? I remember seeing some tolerances = rounding around research.

Re: [0.16.36] Rounding error with modules?

Posted: Wed May 02, 2018 12:05 pm
by kitcat
Rseding91 wrote:The game doesn't round numbers.
Maybe not internally, but it at least does something for display. If it doesn’t round(), does it floor()?

Re: [0.16.36] Rounding error with modules?

Posted: Wed May 02, 2018 2:57 pm
by uukgoblin
I call floor(41.999) an "improper rounding" of that number :-) Especially when the result is 41.9. That's definitely incorrect, even for a floor :-)

Re: [0.16.36] Rounding error with modules?

Posted: Wed May 02, 2018 3:22 pm
by c0bRa
just do floor(41.9999+0.5f) that should do the right thing... ;)

Re: [0.16.36] Rounding error with modules?

Posted: Thu May 03, 2018 8:10 pm
by Rseding91
Unless one of the other devs wants to tinker with this and potentially break a bunch of stuff (ALA rail signals) I'm going to move this to won't fix.

Re: [0.16.36] Rounding error with modules?

Posted: Thu May 03, 2018 8:43 pm
by Dominik
I'm ok.

Re: [0.16.36] Rounding error with modules?

Posted: Thu May 03, 2018 9:33 pm
by uukgoblin
OK, but can you please let me know what's the actual power it's consuming? I'm doing some other calculations that rely on this. Thanks!

Re: [0.16.36] Rounding error with modules?

Posted: Thu May 03, 2018 9:39 pm
by Jap2.0
uukgoblin wrote:OK, but can you please let me know what's the actual power it's consuming? I'm doing some other calculations that rely on this. Thanks!
A minuscule fraction of a KW less than one more than is displayed.

Also... the rail signal thing is the kind of thing that in many games would get put into a stable release, when found the devs would say "just replace all your rail signals", and would get fixed 20 bugfix versions and 5 years later.
So I wouldn't say that it's as bad as you're making it out to be. Literally the only thing you're promising in experimental versions is that your computer probably won't explode.