float InvSqrt (float x) {
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}This function appears in the Quake 3 source. It's reportedly about four times faster than 1.0/sqrt(x). There's a
paper on how it works, and whence the magic number. Wow. (Link
(
Read more... )