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
- “quake 3 fast inverse square root explained” (google.com)
- Fast inverse square root (en.wikipedia.org)
- Quake III Arena (en.wikipedia.org)
- IEEE 754 (en.wikipedia.org)
the trick: a float's bits read as an integer are roughly its logarithm
- Newton's method (en.wikipedia.org)
- “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
- Ocarina of Time any% barely involves playing Ocarina of Time · Ludovica Ferri · 5 sources
- the PlayStation started as a CD add-on for the Super Nintendo · Ludovica Ferri · 5 sources
- Flash stopped on January 12, 2021, and people saved 160,000 games · Ayodele Bankole · 7 sources
- the four color theorem was the first big proof nobody could check by hand · Henrik Larsen · 5 sources