
Float inverse square root approximation 

Code 
01: float invSquareRootFastest(float x)
bits.stephanbrumme.com

Explanation 
The inverse square root can be rewritten with an exponent: 1/√(x) → x^{½} When x already is expressed with an exponent, say x → a^{b}, then 1/√(x) → 1/√ a^{b} → a^{b/2} TODO 
Restrictions 
• designed for positive 32 bit floats • approximation, average deviation of ≈ 5%  for example: √144 = 12, but squareRoot(144) = 12.5, ≈ 4% off 
These ads help me to pay my server bills 

Performance 
• constant time, data independent • 2.67 GHz Intel® Pentium™ D805, Microsoft Visual C++ 2005, highest level of optimization: ≈ 950 million numbers per second ≈ 3 cycles per number • 2.67 GHz Intel® Pentium™ D805, GCC 3.4.5 (MinGW), highest level of optimization: ≈ ??? million numbers per second ≈ ? cycles per number CPU cycles (full optimization, lower values are better) 
Download 
The full source code including a test program is available for download. A precompiled Windows commandline executable (66 kB) is available as well. 
References 
Quake3 source code Chris Lomont, "Fast Inverse Square Root" 
More Twiddled Bits 
... or go to the index 