Incorrect substantiation of the issue :
I get a Lua format error message:
integer overflow trying to keep -1. # IND
The variable type(n) really number , and I can format it as a string (i.e. %s ), but it is not a number, for example:
print(string.format("value=%s, type=%s", n, type(n)));
for value NaN returns:
value = -1. # IND, type = number
I want to fix this, but I have no idea who generates this NaN (Lua has no debugger).
So all I have to do is reset a lot of asserts all over the code, until I can bind this discontinuous NaN value to the source.
But I can not find any condition that traps him, and Lua does not have isnan(x) .
Question
How can I check the 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 he prints
value = -1. # IND, number
Update two . Just in case, I missed something, my actual code:
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 outputs of the faulty value:
Not NaN: labelNumber = 4, formatString = "% d", oldValue = -1. # IND (number)
Update three
While trying to solve this problem, I just noticed the absurdity of reality:
function isnan(x) if type(x) ~= "number" then return false; --only a number can not be a number end; ... end;