[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Formatting numbers without precision loss
- From: Hartmut Henkel <hartmut_henkel@...>
- Date: Tue, 20 Jun 2023 14:34:32 +0200 (CEST)
On Tue, 20 Jun 2023, 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