Skip to content

Instantly share code, notes, and snippets.

@DavidHulsman
Created October 9, 2012 19:43
Show Gist options
  • Save DavidHulsman/3860985 to your computer and use it in GitHub Desktop.
Save DavidHulsman/3860985 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment