Two Case Studies of NaN
# Summary
IEEE-754 NaN (Not a Number) violates implicit assumptions in programming language design, causing unexpected behavior in two cases: Python's list equality comparison assumes reflexivity (that objects equal themselves), but NaN != NaN, leading to inconsistent behavior where `[nan] == [nan]` is True despite `nan == nan` being False. In Lua's numerical for-loops, NaN produces unintuitive results because the implementation's specific comparison operators (like `<` and `<=`) behave unpredictably with NaN, causing loops to execute unexpectedly or never at all depending on where NaN is used as the initial value, limit, or step.
Read Full Article →