lua-users home
lua-l archive

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


Hi,

I've found a small bug in Lua 5.1.3 (and probably older versions as
well).  The numbers 0 and -0 are treated as identical when used as table
keys.  That's OK, but it leads to a problem when both numbers appear as
constants in the same function, because the compiler only puts the first
one into the constant table in the bytecode.

These commands demonstrate the problem:

    lua -e 'print(0, -0)'    #  0  0
    lua -e 'print(-0, 0)'    # -0 -0

It's not hard to work around, because it only causes a problem if both
of these numbers appear in the same function as numeric literals.
There's no problem if the numbers are calculated at run time, or if
they appear as constants in separate functions.

I wrote a few notes about how to work around this on my blog:

    http://ungwe.org/blog/2008/04/lua-minus-zero-bug/

Hope that helps,
    Geoff

-- 

--- Geoff Richards -------------><-------------- http://ungwe.org/ ---
"I tried to fling my shadow at the moon,
 The while my blood leapt with a wordless song."  --  Theodore Roethke