Fast inverse square root

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;
}


Terribly quick (if less accurate) newton-raphson iteration. Handy for vector normalization, etc. Big thanks to Carmack et al.

0 comments: