Skip to content
Loading page

Started by Ludovica Ferri (@ludo_) ·

0x5F3759DF

The famous magic number in the Quake III source, with the very honest comment next to it. It wasn't even invented at id; people traced it back to earlier graphics work.

6 sources · 47 min down the hole

How I got here

Started with
“quake 3 fast inverse square root explained”
Ended at
“fast inverse square root origin”

The Trail

  1. “quake 3 fast inverse square root explained” (google.com)
  2. Fast inverse square root (en.wikipedia.org)
  3. Quake III Arena (en.wikipedia.org)
  4. IEEE 754 (en.wikipedia.org)

    the trick: a float's bits read as an integer are roughly its logarithm

  5. Newton's method (en.wikipedia.org)
  6. “fast inverse square root origin” (hn.algolia.com)

    the threads tracing who actually wrote it are a whole detective story

What I came away with

Read a float's bits as an integer and you get roughly its logarithm, so one shift and a subtraction from a magic constant give a decent first guess at 1/√x. One step of Newton's method cleans it up. Modern CPUs have a dedicated instruction for this, so it's a museum piece now.

Keep going