Game Development 4 min read

Unveiling the Fast Inverse Square Root: How a 1999 Game Engine Cut Computation Time by 4×

The Fast Inverse Square Root algorithm, invented by John Carmack for Quake III Arena, uses a clever magic constant and Newton‑Raphson iteration to compute 1/√x far faster than traditional methods, dramatically reducing floating‑point workload in real‑time graphics.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unveiling the Fast Inverse Square Root: How a 1999 Game Engine Cut Computation Time by 4×

John Carmack, a legendary programmer in the game industry, needed an extremely efficient way to compute the inverse square root for lighting and projection calculations while developing Quake III Arena in 1999, where millions of such operations were performed each second.

He devised the Fast Inverse Square Root algorithm, which starts with the hexadecimal constant 0x5f3759df and applies a single Newton‑Raphson iteration to obtain a close approximation of 1/√x. This method runs about four times faster than conventional approaches, making it ideal for high‑performance game graphics.

float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = *( long * ) &y;               // evil floating point bit‑level hacking
    i  = 0x5f3759df - ( i >> 1 );       // what the fuck?
    y  = *( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
    // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, optional

    return y;
}

The algorithm’s primary value lies in its ability to drastically cut the number of floating‑point operations required for real‑time rendering, which was a breakthrough for game graphics performance at the time.

The mysterious magic constant 0x5f3759df remains unexplained; later researchers have proposed alternative constants that can be even more efficient, yet the original constant’s effectiveness continues to be celebrated in the graphics community.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

algorithmGame Developmentfloating-pointFast Inverse Square RootCarmackgraphics optimization
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.