lua-users home
lua-l archive

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


What regressions are the developers trying to catch with this test?

assert(not pcall(string.format, "%d", 2^63))

-- James

On Thu, Jun 18, 2015 at 12:17 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> > 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