Cool Code – Quake 3 Fast InvSqrt()

Ever play Quake while growing up? Aside from the game itself, the code written to build it is home to a small piece of history in being able to get around the very expensive inverse square root function using very accurate, very fast approximation.

The code, specifically how the mythical constant(0x5f3759df) was derived is still a bit of a mystery:

“[The constant] is actually doing a floating point computation in integer – it took a long time to figure out how and why this works, and I can’t remember the details anymore.” – Gary Tarolli (Partial Code Author)

Read more about it –