Found this interesting, and also it made me feel stupid because - TopicsExpress



          

Found this interesting, and also it made me feel stupid because people can figure out stuff like this. float FastInvSqrt(float x) { float xhalf = 0.5f * x; int i = *(int*)&x; // evil floating point bit level hacking i = 0x5f3759df - (i >> 1); // what the ****? x = *(float*)&i; x = x*(1.5f-(xhalf*x*x)); return x; } This piece of code finds the approximate inverse square root of a number by interpreting the bits of a floating point as an integer, performing voodoo integer math on it, and reinterpreting it as a float. Its well known for being used in Quake III Arena. Article provides proof for why it works and where 0x5f3759df come from.
Posted on: Tue, 28 Oct 2014 06:38:49 +0000

Trending Topics



Recently Viewed Topics




© 2015