# NaN Is Never Equal to Itself, Except When It Is

Original title: If It Floats

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

▲ 49 · by [surprisetalk](<https://news.ycombinator.com/user?id=surprisetalk>) · 💬 3
[original](<https://blog.coredump.cx/p/if-it-floats>) · [HN discussion](<https://news.ycombinator.com/item?id=50693725>)

## Summary

A tour of floating-point absurdities in C and JavaScript: NaN fails every equality check yet can equal itself as an array index, NaN ** 1e-350 returns 1, and ~NaN equals ~Infinity. JavaScript's float-backed arrays let foo[1e16 + 1] retrieve what was stored at foo[1e16], and a loop starting at 1e16 never terminates. The sign of NaN even reveals whether a CPU is x86 or ARM.

## Key quote

> In C, because NaN is not a number, it can be positive or negative. This is a common way to detect knock-off CPUs.

---

## Cite

- Page: https://zeli.app/story/50693725
- Date: 2026-11-29
- Source: blog.coredump.cx (https://blog.coredump.cx/p/if-it-floats)
- Hacker News: https://news.ycombinator.com/item?id=50693725

## Other languages

- zh: https://zeli.app/zh/story/50693725 · markdown: https://zeli.app/zh/story/50693725.md
