Fennel with LuaJIT compiles 141791343654238
into 1.4179134365424e+14
(141791343654240
).
This does not happen with PUC Lua 5.3.
Welcome to Fennel 1.4.2 on LuaJIT 2.1.1693350652 Linux/x64!
Use ,help to see available commands.
>> 141791343654238
1.4179134365424e+14
>> (string.format "%0.f" 141791343654238)
"141791343654240"
Welcome to Fennel 1.4.2 on PUC Lua 5.3!
Use ,help to see available commands.
Try installing readline via luarocks for a better repl experience.
>> 141791343654238
141791343654238
>> (string.format "%0.f" 141791343654238)
"141791343654238"
See Fennel shows the same problem. In both directions. 141791343654238 => 141791343654240.0
print(string.format("%0.f", 141791343654238)) Works correctly on all lua versions, so the inaccuracy is coming from fennel
The inaccuracy is coming from LuaJIT's
tostring
:$ luajit LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/ JIT: ON SSE3 SSE4.1 BMI2 fold cse dce fwd dse narrow loop abc sink fuse > print(tostring(141791343654238)) 1.4179134365424e+14
So I guess we just need to find the right format specifier that will work across integers and floats.
I think this ought to be fixed in 08d25cb.