Created
October 28, 2014 08:47
-
-
Save Tab3r/cbc669b6deb7e84019e5 to your computer and use it in GitHub Desktop.
Fast Inverse Square Calculation
This file contains hidden or 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 FastInvSqrt(float x) { | |
float xhalf = 0.5f * x; | |
int i = *(int*)&x; // evil floating point bit level hacking | |
i = 0x5f3759df - (i >> 1); // what the fuck? | |
x = *(float*)&i; | |
x = x*(1.5f-(xhalf*x*x)); | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment