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: <http://www.netlib.org/fp/>
> 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
http://lua-users.org/lists/lua-l/2002-08/msg00193.html

> 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 http://lua-users.org/lists/lua-l/2004-12/msg00027.html