wiki wrote:Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants
That's what I meant.
Anyway, the magic number mentioned in the comic (0x5f375a86) refers to this: http://en.wikipedia.org/wiki/Fast_inverse_square_root
tl;dr version:
Computers can't do square root very fast. In fact it can be hundreds of times slower than addition/subtraction/multiplication.
Computer games need a shitload of square root calculations for physics simulation, and they need them FAST. Approximate methods are usually used.
At some point, years after the game was published, someone made public the inverse square root calculation method in Quake III Arena. The interesting bit is this: (also it has the original comments)
- Code: Select all
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the f*ck?
y = * ( float * ) &i;
I can't really explain what's going on there, but besides the magic number poping out of nowhere, nothing really makes sense in those 3 lines. If you saw it without context you'd think it's some guy who just picked up a "Learn C in 20 days" book and is writing out gibberish.
However this method turns out to have been faster than any other method known at the time(maybe it still is, I dunno). Also no one knows exactly where the code originates. Judging from the comments it's pretty clear the Quake guys didn't write it themselves.
tl;dr tl;dr
0x5f3759df is magic yo. Aliens probably did it.