Two Case Studies of NaN

The cursed number glitch that made coders yell, joke, and ask why computers do this

TLDR: A programmer showed how a special broken-number value can make Python and Lua behave in deeply unintuitive ways, exposing hidden assumptions in their design. Commenters turned that into a mini-drama about sloppy software rules, with one camp furious and another just posting pure bewilderment.

A delightfully nerdy post about the weirdest number in computing somehow turned into a full-on comment-section mood swing. The core reveal is simple enough for civilians: there’s a special “not a real number” value, called NaN (“not a number”), and when it sneaks into programming languages, perfectly normal rules start acting haunted. In Python, a NaN can be unequal to itself but still make a one-item list look equal. In Lua, dropping NaN into a counting loop creates results that feel less like math and more like a cursed carnival game.

And the community reaction? Equal parts outrage, confusion, and comedy. One commenter came in swinging with a broadside against years of messy software design: “Just store what you mean to store for gods sake.” That sparked the biggest vibe of the thread — frustration that computers keep treating missing, broken, and special values like they’re all the same family drama. Another commenter simply replied “Wat.”, which honestly may be the most accurate summary of the whole NaN experience. There was even a drive-by link-drop to a related Hacker News discussion, because apparently this bizarre number behavior has become a recurring series.

The real entertainment here is that nobody seems shocked NaN is weird — they’re shocked by how many normal language features quietly assume the world makes sense. And when NaN shows up, the illusion collapses instantly.

Key Points

  • The article argues that NaN exposes implicit assumptions in programming language design because NaN does not compare equal to itself.
  • In Python, `nan == nan` is `False`, but `[nan] == [nan]` can be `True` because list equality first compares elements by identity.
  • The article cites Python documentation that says equality should be reflexive when possible, an assumption NaN violates.
  • In PUC-Rio Lua, numerical `for` loops produce unintuitive results when NaN is used as the initial value, limit, or step.
  • The article suggests Lua should explicitly reject NaN in numerical `for` loops, noting that it already errors on a zero step.

Hottest takes

"Just store what you mean to store for gods sake" — whatever1
"We have been fighting with over-designed bs for decades" — whatever1
"Wat." — fragmede
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.