Irrelavent justification for the question:
i'm getting an error calling Lua format
:
integer overflow attempting to store -1.#IND
The variable's type(n)
really is a number
, and i can format
it as a string (i.e. %s
), but it's not a number, e.g.:
print(string.format("value=%s, type=%s", n, type(n)));
for the NaN
value returns:
value=-1.#IND, type=number
i want to fix this, but i have no idea who is generating this NaN
(Lua has no debugger).
So i'm left with having to throw a lot of asserts
all over the code until i can pin down to the source of this intermittent NaN
value.
But i can't find any condition that traps it, and Lua doesn't have isnan(x)
.
Question:
How can i test a number for -1.#IND
in Lua?
Update:
i tried:
if (n ~= n) then
print(string.format("NaN: value=%s, type=%s", n, type(n)));
else
print(string.format("value=%s, type=%s", n, type(n)));
end;
and it prints
value=-1.#IND, number
Update Two: Just in case i missed something, my actual code is:
if (oldValue ~= oldValue) then
print(string.format("Is NaN: labelNumber=%d, formatString=\"%s\", oldValue=%s (%s)", labelNumber or 0, formatString or "nil", oldValue or "nil", type(oldValue)));
else
print(string.format("Is not NaN: labelNumber=%d, formatString=\"%s\", oldValue=%s (%s)", labelNumber or 0, formatString or "nil", oldValue or "nil", type(oldValue)));
end;
And the faulty value outputs:
Is not NaN: labelNumber=4, formatString="%d", oldValue=-1.#IND (number)
Update Three
Still trying to solve this problem, i just noticed the absurdadity of reality:
function isnan(x)
if type(x) ~= "number" then
return false; --only a number can not be a number
end;
...
end;