Action summary
John Carmack Fast inverse Square root algorithm
John Carmack’s fast inverse square root function is a famous algorithm used in computer graphics, particularly in 3D rendering, to compute the inverse square root of a number quickly.
It was notably used in the Quake III Arena game engine to speed up computations related to lighting, shading, and physics. The function approximates the value of 1/sqrt(x) very efficiently, significantly faster than the traditional method of calculating a square root followed by division.
Version notes
evil floating point bit level hacking
John Carmack’s fast inverse square root algorithm is a clever and highly efficient method for computing the inverse square root of a floating-point number. This algorithm became particularly famous because of its use in the game engine of Quake III Arena, a groundbreaking first-person shooter game developed by id Software. The inverse square root is used in a variety of calculations in 3D graphics, particularly for normalizing vectors (which is essential for lighting, physics, and camera calculations). Carmack’s algorithm made these operations significantly faster.
While Carmack’s inverse square root algorithm was a big deal for its time, modern hardware (especially GPUs) now includes very fast, specialized instructions for computing square roots and inverse square roots. As a result, the need for such a trick has diminished. Additionally, floating-point precision and concerns about the limitations of the method (accuracy in some edge cases) mean that more exact methods are now preferable in many applications.
John Carmack’s fast inverse square root algorithm was a brilliant optimization that came at a time when every bit of performance mattered for real-time 3D graphics. Its combination of clever bit manipulation and numerical refinement made it possible to perform a common but expensive operation much more efficiently, helping games like Quake III achieve smoother and faster performance.