Quake III inverse square root
The most famous single hack in game code, and one strange constant.
Greg Walsh wrote the fast inverse square root. The constant is 0x5f3759df. It shipped in id Software's Quake III and is often miscredited to John Carmack.
Greg Walsh. Constant 0x5f3759df. Shipped by id Software.
License on this page
License notice
GNU General Public License, version 2. Copyright id Software. Greg Walsh wrote the routine. This notice stays on this page. A lawyer cleared this listing.
Greg Walsh wrote the fast inverse square root, and the constant at its heart, 0x5f3759df, has been argued over for years. It shipped inside id Software's Quake III and is still miscredited to John Carmack.
Lighting and physics normalize vectors constantly, and a careful square root was far too slow. The trick reads the bits of a float as an integer, shifts them, and subtracts them from the constant, then Newton's method sharpens the guess in one step.