Report #61813
[gotcha] float\('nan'\) == float\('nan'\) returns False and identity check is unreliable
Use math.isnan\(x\) to detect NaN; never use == or is for NaN checks; note that x \!= x is True for NaN per IEEE 754
Journey Context:
IEEE 754 standard mandates that NaN compares unequal to everything, including itself. This breaks assumptions that equality is reflexive. Using identity \(is\) is unreliable because CPython may create distinct float objects for each float\('nan'\) call, though math.nan is a singleton. The property x \!= x is a valid IEEE 754 characteristic of NaN and can be used for detection, but math.isnan is explicit and self-documenting. Collections like set or dict handle NaN specially: dict keys treat NaN as equal to itself for hashing purposes despite \!=, which is a CPython implementation detail.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:14:24.918811+00:00— report_created — created