July 14, 2026
NaN of Your Business
Two Case Studies of NaN
The number that breaks the rules has coders laughing, arguing, and side-eyeing their tools
TLDR: One weird math value made Python and Lua behave in surprising, undocumented ways, exposing hidden assumptions in how these languages work. Commenters loved the chaos, joked about even stranger math rules, and argued this may be less about one cursed value and more about shaky number handling overall.
A tiny programming deep-dive turned into a full-on "wait, what?" moment when readers were shown how NaN—the special computer value that basically means "not a real number"—can make popular languages act completely bizarre. In Python, the shocker is that a NaN doesn’t equal itself, yet a list containing that same NaN can still come out looking equal in some cases. In Lua, things get even messier: drop NaN into a counting loop and the loop may run once, never run, or act upside down depending on where the NaN lands. The big mood from the community was equal parts delight and dread: this is hilarious, but also exactly the kind of weird edge case that makes programmers lose a weekend.
The funniest reaction came from jjgreen, who highlighted the absurd-sounding rule "hypot(Inf, NaN) == Inf" and basically summed up the thread’s energy: people were not just learning, they were cackling. Others piled on with links to older NaN weirdness, turning the whole thing into a mini cinematic universe of broken assumptions. But not everyone was just there for the jokes. One hot take argued you don’t even need NaN to get nonsense in Lua—huge floating-point numbers are enough—which nudged the debate from "NaN is cursed" to "maybe mixing number types was the real trap all along." In other words: the article exposed a niche bug, and the comments instantly upgraded it into a broader roast of how fragile programming languages can be when one weird value walks into the room.
Key Points
- •The article presents two case studies showing how NaN can expose hidden assumptions in programming-language design.
- •In Python, `nan == nan` is `False`, but `[nan] == [nan]` is `True` because list equality first compares elements by identity.
- •The article says Python's behavior reflects a common assumption, also noted in the Python 3 reference manual, that identical objects compare equal to themselves.
- •In Lua numerical `for` loops, using NaN as the initial value, limit, or step leads to unintuitive execution patterns due to internal comparison checks.
- •The article suggests Lua should explicitly reject NaN in numerical `for` loops, similar to its existing rejection of a zero step.