lua-users home
lua-l archive

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

On Sun, Sep 8, 2013 at 1:48 PM, Dirk Laurie <> wrote:
> 2013/9/8 Coda Highland <>:
>> while tostring(tonumber(x)) can't be a guaranteed round-trip,
>> tonumber(tostring(x)) CAN be, by making tostring() output enough
>> digits.
> For a certain meaning of "enough", yes. Is "enough" 17 digits,
> though? Interesting but decidedly non-trivial question!

It's not non-trivial at all. It's actually a fairly well-known result.
17 digits is sufficient to uniquely identify every possible
double-precision floating point number. Certainly you can't precisely
express some values in 17 digits but no two double-precision IEEE
floats map to the same 17-digit number.

> Do we really want "tostring(0.1)" to return "0.10000000000000001"?

Yes, I think we do. If you wanted something to LOOK pretty, instead of
having it be CORRECT, you wouldn't use tostring() -- you'd be using

/s/ Adam