lua-users home
lua-l archive

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


Ralph Hempel wrote:
> Doug Rogers wrote:
>> Still, 2^31 as a positive number should not result in -2^31 when used as
>> a key.
> Are you sure? I think it's the biggest negative number there
> is in the range of 32 bit signed integers...

True, 2^31 = 0x80000000 which, when using 32-bit signed integers, is the
representation of the lowest negative integer in the range. The language
definition doesn't confine numbers to that range. In fact, most
implementations use double precision floating point. In that case
(IEEE-754) 2^31 is exactly representable as a positive integer.

Other languages might have completely different ways of managing the
representation of numbers. Ada throws an exception if you try to use a
value of 2^31 when the range is -2**31 .. 2**31 - 1. Common Lisp moves
from register-like integers to bignums to rationals to reals (floating
point) to complex mixtures of them. That can be fun, but can also get in
the way sometimes.

But none of that really suitable for Lua.

What is required, though, is that the value supplied as a key be used as
the key. A table should be indexable by both 2^31 and -2^31. In this
case it is not. Hence the erroneous implementation and the need for a fix.

Doug

-- 
Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220