Skip to content

Instantly share code, notes, and snippets.

@kemadz
Created July 9, 2013 01:41
Show Gist options
  • Save kemadz/5954003 to your computer and use it in GitHub Desktop.
Save kemadz/5954003 to your computer and use it in GitHub Desktop.
#include <stdio.h>
float InvSqrt(float x)
{
float xhalf = 0.5f * x;
int i = *(int*)&x;
i = 0x5f375a86 - (i>>1);
printf("%d", i);
x = *(float*)&i;
printf("%f", x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
return x;
}
int main(int argc, char *argv[])
{
printf("%f\n", 1.0f / InvSqrt(15.3f));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment