[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Bug in storing -0 constant
- From: Geoff Richards <Ni1phahs@...>
- Date: Sun, 6 Apr 2008 12:03:18 +0100
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:
Hope that helps,
--- 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