I ran across
this article (and
follow up article) today and had to read it though twice. It was simply great for a former graphics geek like me.
The article is basically about the history behind this little C hack:
CODE
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 code and its like are not seen in most modern programs. It may hide somewhere in the basement of a graphics library or physics engine but not in the application code.
The code is a simplified version of the
Newton-Raphson's method applied to approximating 1/sqrt(x). It is an amazing little bit-twiddling hack that calculates a good "first guess" which optimizes the NR-Method so that it converges faster.
The article was great to read because it ran past the names of iconic names in graphics programming:
John Carmack,
Michael Abrash, Terje Mathisen (who I had never head of), and Gary Tarolli.
..you just don't see code like this anymore...
The *magic* behind the code is eventually ascribed to Clive Moler -- the inventor of MatLAB. Amazing little piece of code!