[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string format help
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 18 Jun 2015 16:17:04 -0300
> > One fix is use Lua 5.2.2 or later, which at least complains:
> >
> > Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> > > print(string.format('%d', 2^63))
> > stdin:1: bad argument #2 to 'format' (not a number in proper range)
> >
> > It already does that on x86 on 5.2.1, but not on sparc. Both are running
> solaris.
The check relies on non-standard C. It converts the double to long long
and then converts ib back to double, seeing whether the result is equal
the original. If so, it assumes that long long can safely represent
the number. C gives no garanties about what happens when it converts
an out-of-bound double (e.g., 2^63) to long long. Probably that is the
reason why it works on x86 but not on Sparc.
-- Roberto