Created
November 13, 2014 17:27
-
-
Save everettcaleb/b1b8b2c9d27d536679b2 to your computer and use it in GitHub Desktop.
Fast (not exact) Inverse Square Root (from Quake source code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float fast_inverse_sqrt(float number) | |
{ | |
long i; | |
float x2, y; | |
const float threehalfs = 1.5F; | |
x2 = number * 0.5F; | |
y = number; | |
i = *(long*)&y; | |
i = 0x5f3759df - (i >> 1); | |
y = *(float*)&i; | |
y = y * (threehalfs - (x2 * y * y)); | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment