Skip to content

Instantly share code, notes, and snippets.

@everettcaleb
Created November 13, 2014 17:27
Show Gist options
  • Save everettcaleb/b1b8b2c9d27d536679b2 to your computer and use it in GitHub Desktop.
Save everettcaleb/b1b8b2c9d27d536679b2 to your computer and use it in GitHub Desktop.
Fast (not exact) Inverse Square Root (from Quake source code)
float fast_inverse_sqrt(float number)
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = *(long*)&y;
i = 0x5f3759df - (i >> 1);
y = *(float*)&i;
y = y * (threehalfs - (x2 * y * y));
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment