Skip to content
DevMeme
124 of 7435
When int and float clash, SuperNaN swoops in to clarify types
CS Fundamentals Post #157, on Feb 21, 2019 in TG

When int and float clash, SuperNaN swoops in to clarify types

Why is this CS Fundamentals meme funny?

Level 1: The Bird-Plane Argument

A crowd stares at the sky, arguing the way crowds always do in superhero movies: half shout "It's a bird!" — well, here, "It's an int!" — and the other half shout "It's a float!" Then the caped figure swoops in and the answer is: neither! It's SuperNaN — the computer world's official way of saying "that math made no sense, so the answer is Nonsense." The funny part is that Nonsense got its own superhero costume. It's like arguing whether the thing in the sky is a bird or a plane, and it turns out to be a flying question mark — and instead of being upset, everyone cheers, because at least now the argument is over.

Level 2: Meeting Not-a-Number

The cast of the comic:

  • int: a whole number type — 42, -7. No decimals, exact arithmetic.
  • float: a number with a decimal point — 3.14 — stored in a format that trades exactness for range.
  • NaN ("Not a Number"): the special float value a computer produces when math goes off the rails:
0 / 0            // NaN
Math.sqrt(-1)    // NaN
parseInt("hello") // NaN
NaN === NaN      // false  (!)
typeof NaN       // "number" (!!)

The two exclamation-point lines are the rite of passage. Your first NaN bug usually looks like a form field: a user leaves "quantity" blank, parseInt("") returns NaN, your total becomes NaN, and your check if (total === NaN) never fires because nothing equals NaN. The fix is Number.isNaN(total) (or isnan() in Python/C). Once you've lost an afternoon to this, the comic stops being abstract: NaN really does behave like a being from another planet who is legally classified as a number, immune to comparison, and capable of flying through your entire calculation untouched.

Level 3: Faster Than a Speeding Exception

The hacktoon comic restages the Superman intro with typological panic. The crowd splits across a jagged divider — "It's an int!" versus "It's a float!" — the two great tribes of numeric representation arguing over what's in the sky, until the caped figure with NaN on its chest resolves the debate by transcending it: "No! It's SuperNaN!"

The satire works because the int/float dichotomy is the first classification scheme programmers learn, and NaN is the canonical counterexample that the scheme leaks. The senior-engineer recognition isn't the pun — it's the propagation. NaN is the silent passenger of numeric code: one division of zero by zero in a metrics pipeline and, hours later, every average, every aggregate, every chart downstream reads NaN, because nearly any arithmetic touching NaN yields NaN. No exception thrown, no stack trace, no crash — just a quiet poisoning of every value it meets, discovered only when a dashboard flatlines or a customer asks why their invoice total is NaN. The hero's flight path is the dataflow graph.

And the debugging experience is shaped by the self-inequality. The naive check if (x == NaN) is always false — a trap nearly every developer falls into exactly once — so languages ship dedicated detectors (isNaN(), Number.isNaN(), math.isnan()), and the old idiom x !== x remains the only equality-based test that works. There's genuine elegance under the comedy: the comic's crowd cheers a value whose superpower is refusing classification, and that refusal is not a bug but the most rigorously specified behavior in numeric computing. The villain origin story, of course, is when SuperNaN lands in production at month-end billing.

Level 4: The Bit Pattern of Heroism

The cape is earned: NaN is one of the strangest citizens of the IEEE 754 floating-point standard, and its weirdness is structural, not accidental. A binary64 double consists of 1 sign bit, 11 exponent bits, and 52 significand bits. When the exponent field is all ones and the significand is nonzero, the value is NaN — which means NaN isn't one value but a family of 2⁵³ − 2 distinct bit patterns, all answering to the same name. The standard even splits them into quiet NaNs (propagate silently through arithmetic) and signaling NaNs (intended to raise an exception when touched), with the significand's leading bit as the distinguishing flag.

Why does NaN != NaN? Because the 754 committee needed a way to detect NaN in an era before isnan() was universally available, and because semantically NaN means "the result of an undefined operation" — 0/0, ∞ − ∞, sqrt(-1) — and two undefined results have no business being declared equal. The reflexivity-breaking comparison is the standard's deliberate design: equality on floats is defined such that NaN compares unequal to everything, including itself. This single decision ripples through all of computing: it breaks the contracts of hash maps and sorted containers (Java's compareTo, C++ std::sort with NaNs is undefined behavior territory), forces languages to invent total-ordering predicates alongside IEEE comparison, and gives JavaScript the legendary typeof NaN === "number" — Not-a-Number is officially a number, because in the type system it is a float bit pattern. Engineers have even exploited the unused NaN payload space for NaN-boxing, packing pointers and type tags inside NaN significands — the technique behind value representations in JavaScriptCore and LuaJIT. The crowd is right to cheer: this thing flies through arithmetic untouched, infects everything it meets, and answers to no equality on Earth.

Description

A black-and-white stick-figure comic is split into two panels. In the top panel, a crowd of office-clad figures point upward, shouting through black speech bubbles: "Look! Up in the sky!", "It's an int!", and "It's a float!", separated by a zig-zag lightning divider. The lower panel counters with a large, bold bubble proclaiming "No! It's SuperNaN!" while a caped superhero, emblazoned with "NaN" on the cape, flies left-to-right above a newly cheering crowd. Faces move from puzzled to delighted, emphasizing the twist that the mystery object is the notorious Not-a-Number value. The gag plays on type confusion, floating-point edge cases, and developer frustration, with the small credit "hacktoon.com" in the bottom left

Comments

7
Anonymous ★ Top Pick SuperNaN: the caped value that turns a five-minute code review into a 45-minute debate about IEEE-754, nullability semantics, and who was bold enough to write `if (x == NaN)` in production
  1. Anonymous ★ Top Pick

    SuperNaN: the caped value that turns a five-minute code review into a 45-minute debate about IEEE-754, nullability semantics, and who was bold enough to write `if (x == NaN)` in production

  2. Anonymous

    After twenty years of explaining to junior devs that NaN !== NaN, I've finally accepted that JavaScript's type system is just performance art disguised as a specification

  3. Anonymous

    SuperNaN's only weakness is identity: even he can't equal himself

  4. Anonymous

    The real irony? In JavaScript, typeof NaN returns 'number', so both camps are technically wrong - and SuperNaN would fail the identity check since NaN !== NaN. Classic IEEE 754 trolling the entire developer community since 1985

  5. Anonymous

    SuperNaN: the only hero whose kryptonite is an equality check - even it ghosts itself with NaN !== NaN

  6. Anonymous

    Int or float? In prod it’s SuperNaN - the IEEE 754 antihero that propagates through every aggregation, defeats equals(), and erases your dashboards

  7. Anonymous

    SuperNaN: the only hero who isn't equal to himself, yet still propagates through your pipeline, ruins your percentiles, and dodges every equality check

Use J and K for navigation