# NaN의 미스터리: Python과 Lua에서 드러난 숨은 함정

Original title: Two Case Studies of NaN

> Hacker News story 48903701 · language: ko · submitted 2026-07-14
> Web version: https://zeli.app/ko/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

IEEE-754의 NaN은 그 자체로 이상한 존재지만, 언어 설계자들이 이를 간과하면서 더욱 기이한 동작이 발생한다. 이 글은 두 가지 사례를 다룬다. 첫째, Python에서 `[nan] == [nan]`이 `True`를 반환하는 이유는 리스트 비교 시 객체 동일성(identity)을 먼저 확인하는 최적화 때문이며, 이는 '동일한 객체는 같다'는 암묵적 가정에 기반한다. 둘째, Lua의 수치 for 루프에서 NaN이 초기값이나 증가폭으로 사용될 때 예측 불가능한 결과가 나오는 현상과 그 원인을 분석한다. 이는 NaN이 비교 연산자에 따라 다르게 동작하기 때문이며, 문서화되지 않은 동작이다. NaN의 특성을 이해하면 프로그래밍 언어 설계의 숨은 가정을 발견할 수 있다.

## Key quote

> NaN을 사용하면 구현에서 사용하는 특정 비교 연산자가 인터프리터의 동작에 그대로 드러나게 된다.

---

## Cite

- Page: https://zeli.app/ko/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

- en: https://zeli.app/story/48903701 · markdown: https://zeli.app/story/48903701.md
- 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
- 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
