Created
December 30, 2020 09:45
-
-
Save NostraDavid/a87af30309e4a870caa6f77b5e9799a1 to your computer and use it in GitHub Desktop.
Inverse Square Root by Greg Walsh
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 invSqrt(float x) | |
{ | |
union { | |
float x; | |
int i; | |
} u; | |
float xhalf = 0.5f * x; | |
u.x = x; | |
u.i = 0x5f3759df - (u.i >> 1); | |
u.x = u.x * (1.5f - xhalf * u.x * u.x); | |
return u.x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a more readable version of the famous invSqrt from idTech 3 (Quake 3 engine), likely created by Greg Walsh.