Two Case Studies of NaN: How Python and Lua Break on Weird Numbers

Two Case Studies of NaN

7theanonymousone💬 3

I explore how IEEE-754 NaN values cause unexpected behavior in programming language design. In Python, list equality optimizations fail because NaN does not equal itself. In Lua, numerical for-loops produce unintuitive results when NaN is used as an initial value or step, revealing undocumented implementation quirks. These cases highlight how implicit assumptions in language semantics often leave NaN unaccounted for.

"NaN is weird, and that means other things behave weirdly with it."

More from this day · 2026-07-14