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

> Hacker News story 48903701 · language: en · submitted 2026-07-14
> Web version: https://zeli.app/story/48903701
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 7 · by [theanonymousone](<https://news.ycombinator.com/user?id=theanonymousone>) · 💬 3
[original](<https://sebsite.pw/w/20260709-nan.html>) · [HN discussion](<https://news.ycombinator.com/item?id=48903701>)

## Summary

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.

## Key quote

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

## HN discussion (3 comments)

### [aragilar](<https://news.ycombinator.com/item?id=48904591>)

> You don't need NaN (or Inf) to have unexpected behaviour with floats and naive loops in lua, using 1e52 is enough. Conflating floating point and integers (independent of encoding) is always a bit of a trap.

### [jjgreen](<https://news.ycombinator.com/item?id=48903841>)

> hypot(Inf, NaN) == Inf
>
> made me laugh out loud ...

### [ColinWright](<https://news.ycombinator.com/item?id=48904416>)

> See also: https://news.ycombinator.com/item?id=48855045

---

## Cite

- Page: https://zeli.app/story/48903701
- Date: 2026-07-14
- Source: sebsite.pw (https://sebsite.pw/w/20260709-nan.html)
- Hacker News: https://news.ycombinator.com/item?id=48903701

## Other languages

- zh: https://zeli.app/zh/story/48903701 · markdown: https://zeli.app/zh/story/48903701.md
- ja: https://zeli.app/ja/story/48903701 · markdown: https://zeli.app/ja/story/48903701.md
- ko: https://zeli.app/ko/story/48903701 · markdown: https://zeli.app/ko/story/48903701.md
- de: https://zeli.app/de/story/48903701 · markdown: https://zeli.app/de/story/48903701.md
- es: https://zeli.app/es/story/48903701 · markdown: https://zeli.app/es/story/48903701.md
