lua-users home
lua-l archive

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


On Fri, April 15, 2011 22:38, Adam Strzelecki wrote:

>>> ( assuming, of course, that 2^31 falls within the range of integers
>>>  which can be represented exactly in the particular Lua
>>> implementation;
>>>  this is certainly the case in the original posting )
>>
>> Nah it doesn't, 31 bits for value + 1 bit for sign, makes 2^31-1 a
>> maximum value you can represent with 32-bit integer. While the result
>> you get -2147483648 is exactly 2^31 casted to 32-bit int, sign bit =
>> 1, value bits all zero 0.

On my platform (pre-compiled Lua binary for Debian 6.0 on Intel x86),
integers up to 2^53-1 are represented exactly, and I have used such
large integers extensively in arithmetic computations without problems.

To quote scripture:

   "The fact is that, when you use a double to represent an integer,
    there is no rounding error at all (unless the number is greater than
    10^14)."  (PiL2, page 10)

My simple wish is that every integer which Lua can represent exactly
should be handled correctly by "string.format" with the "%i" conversion.

------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------