After a discussion about the fast inverse square root function at the office my stubbornness pulled me into the rabbit hole of understanding how it works. This is the function that famously bit-casts a floating-point value to an int, does simple integer arithmetic, and then bit-casts the result back:

int i = * (int*)&x; // evil floating point bit level hacking

i = 0x5f3759df - (i >> 1); // what the fuck?

x = * (float*)&i;

This blog post is my tour of the rabbit hole that is FastInvSqrt.

int i = * (int*)&x; // evil floating point bit level hacking

i = 0x5f3759df - (i >> 1); // what the fuck?

x = * (float*)&i;

This blog post is my tour of the rabbit hole that is FastInvSqrt.