is LUA_NUMBER_FMT_N caused accuracy errors?

46 views
Skip to first unread message

Chenchen Zhuo (lunoctis)

unread,
Dec 18, 2025, 5:26:25 AM (22 hours ago) Dec 18
to lua-l
Lua 5.5.0-rc4 build with default configs (LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE)

in the lua(.exe), input

74.4 / 100

result: 0.74400000000000011

compare to Lua 5.4.6, the value of "LUA_NUMBER_FMT" is "%.14g"
but "%.15g" in Lua 5.5.0, and “LUA_NUMBER_FMT_N" is "%.17g"

after set "LUA_NUMBER_FMT" and "LUA_NUMBER_FMT_N" to "%.14g" and recompile

74.4 / 100

result: 0.744

Roberto Ierusalimschy

unread,
Dec 18, 2025, 1:38:15 PM (13 hours ago) Dec 18
to lu...@googlegroups.com
> after set "LUA_NUMBER_FMT" and "LUA_NUMBER_FMT_N" to "%.14g" and recompile
>
> 74.4 / 100
>
> result: 0.744

The problem is that both expressions are not equal :-)

> 74.4 / 100 == 0.744
false
> 74.4 / 100 == 0.74400000000000011
true

Python(3) and JavaScript (js) give similar results. (0.7440000000000001,
instead of 0.74400000000000011.)

-- Roberto

Roberto Ierusalimschy

unread,
Dec 18, 2025, 1:53:11 PM (13 hours ago) Dec 18
to lu...@googlegroups.com

Chenchen Zhuo (lunoctis)

unread,
Dec 18, 2025, 8:29:31 PM (7 hours ago) Dec 18
to lua-l
thanks for reply, I have no further questions.
Reply all
Reply to author
Forward
0 new messages