One more reason why Quake rules

Being a frag-head, I went to one of those forums by UT fans comparing UT with Quake. Every single thread had the same conclusion, "Though Q3 kicked ass all this time, UT 2004 is pretty good". I can personally give a hundred reasons why quake is the ultimate FPS, this one is simply marvellous.
Check out how quake engine computes 1/sqrt(x)!!
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;
}
The method is around 4 times faster than a call to sqrt() from C library with a very small compromise on precision which is ok for all practical purposes.
The code works using Newton's root finding method:
yn+1 = yn - f(yn)/f'(yn)
which is the code x = x*(1.5f-xhalf*x*x);
yn+1 is the (n+1)th root
yn is the nth root
i = 0x5f3759df - (i>>1) is the nth root.
Cudnt quite understand how the got the magic number. The float to interger conversion is to get the exponent of the float number. The complete details regarding this can be found here.
Nice bit hack! Plus some nice math!!No wonder why Q3 performs well even on 64 mb 733 hz Celeron!!!
John Carmack is God.. is Xaero..
Message for UT
