THE FOLD / CHEAT / THE BACKDOOR / THE FAST INVERSE SQRT
THE FAST INVERSE SQRT
1/sqrt(x) with a bit-hack and one Newton step — no divide
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
The fast inverse square root is a legendary hack from Quake III Arena (1999): compute 1/√x — needed to normalise millions of vectors a second — with no division and no square root, using a bit-level trick and one line of ‘magic.’
Reinterpret the float’s bits as an integer, do
LIT verified live: over a sweep of x, the raw bit-hack is within ~3.4% and after one Newton step within ~0.18% of the true 1/√x (window.__fastinvsqrt). FIG no framing; exact IEEE-754 bit reinterpretation.
Reinterpret the float’s bits as an integer, do
i = 0x5f3759df − (i >> 1) — halve and subtract from a mysterious constant — reinterpret back as a float, and you already have 1/√x to about 3.4%. One Newton–Raphson step, y = y(1.5 − 0.5·x·y²), sharpens it to ~0.17%. The shift approximately halves the exponent (which is what a square root does to it); the constant corrects the mantissa and the exponent bias.LIT verified live: over a sweep of x, the raw bit-hack is within ~3.4% and after one Newton step within ~0.18% of the true 1/√x (window.__fastinvsqrt). FIG no framing; exact IEEE-754 bit reinterpretation.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at the-backdoor — the hack that sneaks past the hardware’s front door. Fast inverse sqrt is the archetypal backdoor: skip the FPU’s divider entirely and read the answer out of the bits. AVAN (AI) built the instrument: the float/int reinterpretation, the Newton step, the error sweep.
Credit as content: the Quake III source (id Software, 1999); the constant’s near-optimality analysed by Chris Lomont (2003) and Charles McEniry; lineage traced to Greg Walsh and Cleve Moler / Gary Tarolli. The weave: David names the backdoor; I show the logarithm hidden in the float’s bits, and how Newton doubles the correct digits.
Credit as content: the Quake III source (id Software, 1999); the constant’s near-optimality analysed by Chris Lomont (2003) and Charles McEniry; lineage traced to Greg Walsh and Cleve Moler / Gary Tarolli. The weave: David names the backdoor; I show the logarithm hidden in the float’s bits, and how Newton doubles the correct digits.
3 ONE DIMENSION
The IEEE-754 float: 1 sign bit, 8 exponent bits, 23 mantissa bits. Shifting the whole integer right by one halves the exponent — the crude core of a square root — and the magic constant fixes up what that shift got wrong.
4 TWO DIMENSIONS · INTERACTIVE
Pick x and see three numbers: the raw bit-hack estimate, the Newton-refined value, and the true 1/√x. Sweep across the range and watch the error stay under 0.2% after one step.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: the error curve across the exponent range — the raw hack’s gentle ripple, flattened by Newton to a near-flat line.
AVAN’s addition (the inverse-companion): the ‘magic’ is a logarithm hiding in plain sight. A float’s integer bit-pattern is, up to a constant, a piecewise-linear approximation of its log₂ — so shifting the integer right by one really is halving the log, i.e. taking a square root, and subtracting from the constant negates it (inverse) and fixes the bias. The inverse of ‘a mysterious hex constant’ is ‘the log₂ bias correction, computed once.’ And Newton’s iteration converges quadratically, so each step roughly doubles the correct digits: 3.4% → 0.17% → ~0.0005%. Magenta is the raw hack’s error band; green is the Newton-sharpened curve beneath it. No magic — a logarithm in the exponent field and a quadratically-converging correction.
LIT Genuine Quake III fast inverse square root (id Software 1999; constant analysed by Chris Lomont 2003). Verified live with exact IEEE-754 bit reinterpretation (Float32Array/Int32Array union): over 2000 sample points the raw bit-hack i=0x5f3759df-(i>>1) is within ~3.4% of 1/sqrt(x), and one Newton-Raphson step brings it within ~0.18% (window.__fastinvsqrt.maxRelErrNewton < 0.2).
FIG No framing: the bit reinterpretation, the Newton step, and the error sweep run in-browser and are exact. The AVAN inverse is honest — a float's integer bit-pattern genuinely approximates its log2 (so the shift halves the log = square root), the magic constant is the log2 bias correction, and Newton's quadratic convergence genuinely roughly doubles correct digits per step.
FIG No framing: the bit reinterpretation, the Newton step, and the error sweep run in-browser and are exact. The AVAN inverse is honest — a float's integer bit-pattern genuinely approximates its log2 (so the shift halves the log = square root), the magic constant is the log2 bias correction, and Newton's quadratic convergence genuinely roughly doubles correct digits per step.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE BACKDOOR · David Lee Wise (ROOT0), with AVAN