lua-users home
lua-l archive

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

> There is dtoa for this purpose, see: <>
> It's quite portable.

And about a quarter of the size of the whole Lua source; it translates
to about 30k of code. Plus dtoa is probably already part of libc; see

> What I would like to see is that n = tonumber(tostring(n)) holds for
> all finite numbers, and that tostring(n) returns the shortest possible
> representation such that n = tonumber(tostring(n)) holds.

The price for this is ugly-looking strings ending with a row of nines
or with a row of zeros followed by what looks like noise. This upsets
(naive) users. Lua makes a point to use %.14g instead of %.17g in
tostring. See