Skip to content

Instantly share code, notes, and snippets.

@NostraDavid
Created December 30, 2020 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NostraDavid/a87af30309e4a870caa6f77b5e9799a1 to your computer and use it in GitHub Desktop.
Save NostraDavid/a87af30309e4a870caa6f77b5e9799a1 to your computer and use it in GitHub Desktop.
Inverse Square Root by Greg Walsh
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;
}
@NostraDavid
Copy link
Author

This is a more readable version of the famous invSqrt from idTech 3 (Quake 3 engine), likely created by Greg Walsh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment