Created
October 15, 2011 21:57
-
-
Save evandrix/1290210 to your computer and use it in GitHub Desktop.
Quake: Inverse Sqrt
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 InvSqrt(float x){ | |
float xhalf = 0.5f * x; | |
int i = *(int*)&x; // store floating-point bits in integer | |
i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method | |
x = *(float*)&i; // convert new bits into float | |
x = x*(1.5f - xhalf*x*x); // One round of Newton's method | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is #038; there?