[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.insert and negative numbers
- From: Matthew Paul Del Buono <delbu9c1@...>
- Date: Wed, 9 Apr 2008 16:53:51 -0400 (EDT)
>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.
>
The table CAN be indexed by both of those indices, distinctly. The problem isn't that, it's that lua_rawgeti takes an integer instead of a lua_Number (perhaps that is a better fix? Though it would reduce performance significantly, I think). As a result, the number is cast to an integer and THEN we have issues beyond the bounds:
> t = {};
> t[2^31] = 1;
> t[-2^31] = 2;
> t[2^500] = 3;
> for k,v in pairs(t) do print(k..[[:]]..v) end
2147483648:1
-2147483648:2
3.2733906078961e+150:3
Thus, table.insert has a problem as it uses lua_rawgeti, but accessing a table directly does not.
-- Matthew P. Del Buono