lua-users home
lua-l archive

Re: Formatting numbers without precision loss

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2023年6月20日, Lars Müller wrote:
> You misunderstood the issue: The given number can be represented
> precisely by a 64-bit float. In fact all integers up to and including
> 2^53 can be represented precisely by 64-bit floats. The issue is just
> that conversion to string rounds "too much" by default, losing
> precision. Thus the round-trip tonumber(tostring(x)) == x fails.
...seems the "double" format in luaconf.h does this:
#define LUA_NUMBER_FMT "%.14g"
...too small to preserve internal precision on print by default.
Regards
Hartmut

AltStyle によって変換されたページ (->オリジナル) /