Skip to content
0:00 / 0:00

#fastinversesquareroot#quakeiii#ieee754

Fast Inverse Square Root — A Quake III Algorithm

Nemean

122K subscribers • 2 videos on Hallway

YouTube
  • Recommended by 5 people: 3 on Hacker News, 1 on Lobsters and 1 in engineering communities.

Intermediate. Assumes working knowledge.

6M views5 years ago5 recommendations

Computer scienceHistory and cultureAlgorithmsMath for programmersHistory of computing

An in-depth explanation of the famous Quake III fast inverse square root algorithm, covering IEEE 754 floating-point representation and Newton's method.

In this video we will take an in depth look at the fast inverse square root and see where the mysterious number 0x5f3759df comes from. This algorithm became famous after id Software open sourced the engine for Quake III. On the way we will also learn about floating point numbers and newton's method. Introduction Why Care? The Code IEEE 754 Bits and Numbers 1st Step: Evil Bit Hack 2nd Step: WTF 3rd Step: Newton Summary Picture of John Carmack is licensed under CC BY 2.0 from author Drew "Prognar" Campbell. Source: flic.kr/p/6YxWYp

Why it's here

5 people recommend this

What people say. Highly recommended as an exceptionally clear and approachable explanation of the math and bit hacks behind the Quake III algorithm.

u/Drach88in r/C_Programming • Recommends

Explanation of Quake III's fast inverse square algorithm

greyfoxon Hacker News • Recommends

On “Copilot regurgitating Quake code, including sweary comments”

Very interesting that this was posted as I literally JUST watched an even MORE interesting youtube upload about this very bit of code just last weekend. Here's the very fun video if anyone wants to take a look: link to this video

Hail_Spacecakeon Lobsters • Recommends

Fast Inverse Square Root — A Quake III Algorithm

colejohnson66on Hacker News • Recommends

On “One does not simply calculate the absolute value”

> The bits of a float as an integer literal are proportional to its log2 value (plus a constant), … I watched a video0 a while back about that. Once that coincidence(?) was explained, Q_rsqrt finally made sense. 0: link to this video (~20 minutes)

infogulchon Hacker News • Recommends

On “Bit Patterns of Float”

Apparently the bit pattern of a float interpreted as an int is sorta-kinda it's own logarithm, which is why the famous fast inverse square root from quake 3 works: log(x^-½) = -½log(x) =~ -log(x) >> 1. This video is approachable and explains it pretty well: link to this video

u/Turrett_99in r/gameenginedevs • Mentions

Game engines code tricks Hi everyone, i just discovered a video that explain how the "fast inverse square root" for Quake 3 works. I instantly got amazed by how an apparently simple problem can be broken apart straight to its root, optimized as much as possible, even by doing some small compromises on precision and tricking bits of data to avoid using more precise but resource-intensive standard c functions. I'm here to ask if someone knows some kind of extreme code optimization such as this in the history of game engine developement or also in other related fields. Have a great day !

u/alex_danikin r/C_Programming • Mentions

On “Weird but legible C programs”

Fast Inverse Square Root algorithm used in Quake III. (see explanation on youtube)

u/deulamcoin r/ProgrammingLanguages • Mentions

Assembly & Assembly-Like Language - Some thoughts into new language creation. I don't know if it was just me, or writing in FASM (even NASM), seem like even less verbose than writing in any higher level languages that I have ever used. It's like, you may think other languages (like C, Zig, Rust..) can reduce the length of source code, but look overall, it seem likely not. Perhaps, it was more about reusability when people use C over ASM for cross-platform libraries. Also, programming in ASM seem more fun & (directly) accessible to your own CPU than any other high-level languages - that abstracted away the underlying features that you didn't know "owning" all the time. And so what's the…

bitwidgeton Hacker News • Mentions

On “Ask HN: What's a small example of some of the best code ever written?”

print("Hello World") /s But I've heard good things about the Fast Inverse Square Root Calculation algorithm in the Doom 3 source code. link to this video

u/daybyter2in r/C_Programming • Mentions

On “What are some of the most insane compiler optimizations that you have seen?”

link to this video One of my alltime favorites...