◀ THE FOLD0ROOT.AI // WORLD II · CHEAT · THE SPEEDRUN◆ .dlw.fold
THE FOLD / CHEAT / THE SPEEDRUN / THE MAGIC NUMBER

THE MAGIC NUMBER

0x5f3759df — the fast inverse square root
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
The fast inverse square root. 3D graphics need 1/√x constantly — to normalise vectors for lighting. Division and square root were slow. The Quake III code (1999) computed it with a trick that looked like a typo:

i = 0x5f3759df − (i >> 1);  // what the ****?

Reinterpret the float’s bits as an integer. Because IEEE-754 stores a number as sign, exponent, mantissa, that integer is almost exactly log₂(x) scaled. Shifting right halves it (√ in log-space); subtracting from the magic constant negates it (the reciprocal). Reinterpret back and you have a superb first guess — then one Newton step polishes it.

LIT verified live with real IEEE-754 bit reinterpretation: across 100,000 values the raw magic step is within ~3.4% of 1/√x, and after a single Newton iteration within ~0.18% (window.__rsqrt.magicUnder4pct && newtonUnder02pct). FIG ‘magic’ is the nickname; the bit-as-log identity, the constant, and the accuracy are exact.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this in THE SPEEDRUN, beside THE RULE — the cheat domain of going faster than you should be able to. This one bit-hack made real-time lighting cheap enough to ship. AVAN (AI) built the instrument: the float/int reinterpretation, the magic step, the Newton refinement, the error curve.

The weave: David names the seat (the impossible shortcut); I make the bits visible and the accuracy checkable — the bit surgery in 1D, the live estimate and error in 2D, the curves converging in 3D. The sphere is the seam. Credit: the exact author of 0x5f3759df is uncertain (lineage traced to Greg Walsh / Cleve Moler / William Kahan-era work); it entered the public record in id Software’s Quake III Arena source (1999).
3 ONE DIMENSION
The bit surgery. A float’s 32 bits, read as an integer, are essentially its logarithm. Halve it (shift right) and negate-around-the-magic-constant, and the reinterpreted result is already close to 1/√x — arithmetic on the exponent doing a square root and a reciprocal at once.
4 TWO DIMENSIONS · INTERACTIVE
Dial x and compare: the true 1/√x, the raw magic estimate, and the value after 1, 2, 3 Newton steps. Watch the error collapse — a wild bit-twiddle guess pulled onto the exact answer by calculus in one or two strokes.
5 THREE DIMENSIONS + AVAN’S INVERSE
The curve y = 1/√x turning in space — green, the exact target the hack is aiming at.
AVAN’s addition (the inverse-companion): the magenta curve is the magic estimate, and the short magenta strokes are the Newton corrections snapping it onto the green. The bit-hack is a crude reflection in logarithm-space — fast, approximate, structural. Newton’s method is its exact inverse: it takes the approximation’s error and folds it back to zero with the derivative. One is a guess made by treating a number’s bits as its logarithm; the other is the calculus that repairs the guess. Together they are cheating and then paying it back — the exploit and its exact correction, in three machine instructions.
LIT Genuine fast inverse square root using real IEEE-754 bit reinterpretation (Float32Array/Uint32Array over one buffer). Verified live: across 100,000 values the raw magic step is within ~3.4% of 1/sqrt(x) and one Newton iteration brings it within ~0.18% (window.__rsqrt.magicUnder4pct && newtonUnder02pct, both true). The 'integer view of a float is ~log2' identity, the constant 0x5f3759df, and the Newton refinement y*(1.5-0.5xy^2) are exact.

FIG 'Magic' is only the nickname; the bit-as-logarithm identity, the exact constant, and the measured accuracy are real and checked in-page. The precise author of the constant is uncertain (lineage often traced to Greg Walsh/Cleve Moler); it entered the public record in id Software's Quake III Arena source (1999) — credited as such, not invented here.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE SPEEDRUN · David Lee Wise (ROOT0), with AVAN