Skip to content

Instantly share code, notes, and snippets.

@evandrix
Created October 15, 2011 21:57
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 evandrix/1290210 to your computer and use it in GitHub Desktop.
Save evandrix/1290210 to your computer and use it in GitHub Desktop.
Quake: Inverse Sqrt
float InvSqrt(float x){
float xhalf = 0.5f * x;
int i = *(int*)&x; // store floating-point bits in integer
i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
x = *(float*)&i; // convert new bits into float
x = x*(1.5f - xhalf*x*x); // One round of Newton's method
return x;
}
@siakc
Copy link

siakc commented May 19, 2022

What is #038; there?

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