[0.16.36] Rounding error with modules?

Things that we don't consider worth fixing at this moment.
Post Reply
uukgoblin
Inserter
Inserter
Posts: 28
Joined: Mon Apr 02, 2018 4:43 pm
Contact:

[0.16.36] Rounding error with modules?

Post 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.

uukgoblin
Inserter
Inserter
Posts: 28
Joined: Mon Apr 02, 2018 4:43 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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?

kitcat
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Wed Apr 26, 2017 3:11 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Dominik
Former Staff
Former Staff
Posts: 658
Joined: Sat Oct 12, 2013 9:08 am
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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.

kitcat
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Wed Apr 26, 2017 3:11 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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()?

uukgoblin
Inserter
Inserter
Posts: 28
Joined: Mon Apr 02, 2018 4:43 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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 :-)

c0bRa
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Sun Nov 13, 2016 8:33 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post by c0bRa »

just do floor(41.9999+0.5f) that should do the right thing... ;)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Dominik
Former Staff
Former Staff
Posts: 658
Joined: Sat Oct 12, 2013 9:08 am
Contact:

Re: [0.16.36] Rounding error with modules?

Post by Dominik »

I'm ok.

uukgoblin
Inserter
Inserter
Posts: 28
Joined: Mon Apr 02, 2018 4:43 pm
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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!

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: [0.16.36] Rounding error with modules?

Post 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.
There are 10 types of people: those who get this joke and those who don't.

Post Reply

Return to “Won't fix.”