moonjit / moonjit

Just-In-Time Compiler for the Lua Programming language. Fork of LuaJIT to continue development. This project does not have an active maintainer, see https://twitter.com/siddhesh_p/status/1308594269502885889?s=20 for more detail.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opt\fold\kfold.lua test fails on MSYS2

joe-92 opened this issue · comments

When updating the Windows documentation I noticed that the following constant folding test (opt\fold\kfold.lua) fails on Windows 10 when using MSYS2 (with gcc 9.2.0):

do --- exp -luajit==2.0
  assert((10^-2 - 0.01) == 0)
end

This can also be reproduced using REPL:

> print(string.format("%.24e", 10^-2))
1.000000000000000194289029e-02
> print(string.format("%.24e", 0.01))
1.000000000000000020816682e-02
> v = 10^-2 - 0.01
> print(string.format("%.24e", v))
1.734723475976807094411924e-18

Does anybody have any idea what's going wrong?

The operation 10^-2 result is imprecise. I suspect this may be because of the way the power is computed and most likely it is the math library pow function. But then it's interesting that Windows 10 native doesn't have this imprecision problem. Does MSYS2 have its own C/math library?

I looked a little bit into it and it seems like the input values of the pow operator are imprecise. If I hardcode the values 10.0 and -2.0 in

case IR_POW - IR_ADD: return pow(x, y); break;

the assertation doesn't fail.

Are you sure that the pow() call remains when you hardcode the values? The compiler will most likely optimise it out.

Any update on this @joe-92 ?