• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


29 Nov, 2024

Updated at 13 Dec, 2024

Why does nan == nan return false?

While experimenting with lua numbers I stumbled upon the following scenario:

local nan = math.sqrt(-1) --math.sqrt(-1) returns nan
print(nan) --should print nan
print(-nan) --should also print nan(not -nan)
print(nan == nan) --this prints false for some reason

Why does the last statement print false? I think this is the first time I encounter a lua variable that doesn’t equal to itself. Due to this I had to do the following workaround:

print(tostring(nan) == "nan")

1 post - 1 participant

Read full topic