Float inverse square root approximation
The inverse square root can be rewritten with an exponent: 1/√(x) → x-½
When x already is expressed with an exponent, say x → ab, then 1/√(x) → 1/√ ab → a-b/2
• designed for positive 32 bit floats
• approximation, average deviation of ≈ 5%
- for example: √144 = 12, but squareRoot(144) = 12.5, ≈ 4% off
help me to pay
my server bills
• 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
lower values are better)
The full source code including a test program is available for download.
A precompiled Windows command-line executable (66 kB) is available as well.
Quake3 source code
Chris Lomont, "Fast Inverse Square Root"
|More Twiddled Bits||
... or go to the index