lua-users home
lua-l archive

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




On Thu, Jun 25, 2015 at 4:31 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 26.06.2015 um 01:04 schröbte James Chang:
What regressions are the developers trying to catch with this test?

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

A signed 64-bit integer usually can represent numbers from -2^63 up to +2^63-1. 2^63 is just out of range.

Correct, but this is more of a meta(?) question. Why include this if lua is intended for x86 chipsets if the behavior for signed long long is always this way? 


-- James

Philipp




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