Skip to content

Instantly share code, notes, and snippets.

@charlietuna
Created April 9, 2014 05:52
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 charlietuna/10229806 to your computer and use it in GitHub Desktop.
Save charlietuna/10229806 to your computer and use it in GitHub Desktop.
Improved (over John Carmack's) inverse square root hack from Řrřola - http://rrrola.wz.cz/inv_sqrt.html
float inv_sqrt(float x)
{
union { float f; uint32 u; } y = {x};
y.u = 0x5F1FFFF9ul - (y.u >> 1);
return 0.703952253f * y.f * (2.38924456f - x * y.f * y.f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment