Page 1 of 1

[0.16.51] Bonus of modules calculated with error

Posted: Fri Aug 03, 2018 6:02 am
by sensenmann
AshenSwift freported on the mod forum of alien-module the following issue: https://mods.factorio.com/mod/alien-mod ... 000a5b9e22

After investigation i have the following problem with this code:

Code: Select all

for i = 1, 100, 1 do
    local levelbonus = i * 0.01
    data:extend({
        {
            [...]
            effect =
            {
                consumption = { bonus = levelbonus },
                speed = { bonus = levelbonus },
                productivity = { bonus = levelbonus }
            },
        },
    })
end
on level 29 the bonus is 28% and on level 58 the bonus is 57% for all other levels the bonus is correct. When i change levelbonus to:

Code: Select all

local levelbonus = i * 0.01001
everything works correctly. If this is not a bug then ignore the issue, this is most likely some floating point rounding issue IMHO.

I can even reproduce it in an online LUA console: https://repl.it/repls/ScornfulBeneficialChapter

Re: [0.16.51] Bonus of modules calculated with error

Posted: Fri Aug 03, 2018 11:54 am
by Rseding91
Thanks for the report however there's nothing we can do about that :) That's just how floating point numbers work.