The Secret Life of NaN

Hiding secret data in “not‑a‑number” has devs yelling genius or chaos

TLDR: NaN, the “not‑a‑number” value in floating‑point math, can hide extra data—fueling clever hacks in programming languages. Devs are split between praising bug‑catching defaults and memory savings, and warning it’s a future booby trap if hardware changes, plus a side debate over quiet vs signaling NaNs.

The internet just discovered that Not‑a‑Number (NaN) isn’t just a math shrug—it’s a secret suitcase. In the IEEE floating‑point standard, NaN can carry hidden bits, and clever hackers use that space to stash other data on the fly. The post and lightning talk sparked a frenzy: half the comments are cheering, half are clutching their calculators.

The loudest fireworks? One camp swears by NaN‑as‑tripwire. In the D language, floats default to NaN instead of 0, which fans say instantly exposes bugs instead of sweeping them under the rug. The pushback is pure drama: critics call it chaos energy—“why is my number broken by default?” Cue memes like “NaN NaN Batman” and “Not A Number? More like Not A Bug.”

Then there’s the “Infinite Hotel” crowd. Devs using NaN to pack lots of value types call it magic—like squeezing extra tenants into a full building. But a doomsday chorus warns it’s built on today’s 64‑bit addresses; if memory use ever grows to the full range, “lots of virtual machines could break.” Meanwhile, a gentler side debate asks if languages should expose only quiet NaN (the non‑exploding kind) since signaling NaN throws errors. Translation: Team Quiet vs Team Loud, with popcorn. For background on NaN and the standard everyone is arguing about, here’s IEEE 754.

Key Points

  • IEEE 754-2008 defines NaN as a special floating-point value; in double precision, NaNs include a 51-bit payload.
  • The NaN payload can be used to encode non-floating-point values and types at runtime (NaN-boxing) in dynamic languages.
  • The standard specifies base-2 formats for powers-of-two bit widths from 16 to 256 bits and base-10 formats from 32 to 128 bits.
  • Binary16 (half-precision) has a 1-bit sign, 5-bit exponent, and 10-bit mantissa; examples illustrate encoded values.
  • IEEE 754 defines special values including ±infinity and quiet/signaling NaN, with guidance on overflow and rounding behaviors.

Hottest takes

“floats get default initialized to NaN, not to 0.0” — WalterBright
“It feels like the Infinite Hotel: you can always add another type” — GMoromisato
“I’d really only need quiet NaN, right?” — jasperry
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.