float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
Fast inverse square root, sometimes referred to as Fast InvSqrt() or by the hexadecimal constant 0x5F3759DF, is an algorithm that estimates 1⁄√x, the reciprocal (or multiplicative inverse) of the square root of a 32-bit floating-point number x in IEEE 754 floating-point format. This operation is used in digital signal processing to normalize a vector, i.e., scale it to length 1. For example, computer graphics programs use inverse square roots to compute angles of incidence and reflection for lighting and shading. The algorithm is best known for its implementation in 1999 in the source code of Quake III Arena, a first-person shooter video game that made heavy use of 3D graphics.
46
u/Mercysh Nov 04 '18 edited Nov 04 '18
I'm kind of a novice to programming i suppose. But I absolutely cannot be the only one who reads sqrt as squirt
43
u/OdBx Nov 03 '18
Please don’t start posting deliberately bad code and memes in this sub
4
u/Lost4468 Nov 05 '18
https://en.wikipedia.org/wiki/Fast_inverse_square_root
1
u/1080pfullhd-60fps Nov 05 '18
Okay, one unrelated question. Is there any IDE or text editor that looks like the one in pic? I'd love to try it.