A dart thrown into the dark abstract of the internet landed on the most famous magic number in graphics code — the trick that computed 1/√x fast enough to light Quake III. We show the technique, credit who actually made it, and ask what I-13 should learn from it. Two prongs, one dart.
THE TECHNIQUE reinterpret · shift · one Newton step
Treat a 32-bit float’s bits as an integer (that integer is an approximation of log₂x), halve-and-subtract from the magic constant, reinterpret back to float — a crude 1/√x — then refine once with Newton’s method. live demo
i = bits_of_float(x)
i = 0x5F3759DF - (i >> 1) // the magic
y = float_of_bits(i) // crude seed
y = y * (1.5 - 0.5*x*y*y) // one Newton iteration
HISTORY & CREDIT credit where it is due
The internet says John Carmack wrote it. He did not — the Quake III source (id Software, GPL’d 2005) carried it, which is why his name stuck. When the dust settled in 2006, the real author stepped forward. cited
1986 · William Kahan & K.C. Ng (UC Berkeley) — the seed idea: bit-fiddle the float, then Newton-iterate. late 1980s · Cleve Moler (Ardent Computer) learns it, passes it to a colleague… late 1980s · Greg Walsh (Ardent) — engineers the algorithm and derives the constant 0x5F3759DF. The real author. ~1994 · Gary Tarolli carries it to 3dfx Interactive’s graphics libraries… 1999 · it surfaces in Quake III Arena (id Software) and becomes legend.
What’s still unknown: how Walsh derived the constant — math, or trial and error. Chris Lomont (2003) later found a marginally better one (0x5F37642F), and asked the same question. open
RECOMMEND FOR I-13 what the galaxy should learn
The whole trick lives in reinterpreting a float as an integer and shifting its bits. I asked the real I-13 compiler whether it can do that. It cannot — proven, not asserted:
i13 check bitshift.i13 => bitshift.i13:2:11 E0102 expected expression (no >> operator)
i13 check bitand.i13 => bitand.i13:3:10 E0001 unexpected character `&` (no bitwise)
i13 run arith.i13 => q = 2.6666666666666665 (only + - * / on f64; no int, no bits)
Recommend: give I-13 an integer view of its numbers and bit operators (>>, &, ^) — ideally as new BinOp discriminants, spending zero new alphabet symbols (the same move the language panel proposed for %). Then a float↔bits reinterpret would let I-13 express this whole family of representation tricks. Tradeoff (honest): I-13’s identity is a counted 13-symbol alphabet and an f64-only `Constant`. Bit-reinterpret assumes a concrete float layout, which the abstract machine currently hides — so this buys expressive power at the cost of a little of the purity. Worth it only if representation-level work is in scope for the galaxy.