#include <stdio.h>
#include <math.h>
float InvSqrt(float x)
{
float xhalf = 0.5f * x;
int i = *(int*)&x; // get bits for floating value
i = 0x5f375a86 - (i>>1); // gives initial guess
x = *(float*)&i; // convert bits back to float
x = x * (1.5f - xhalf*x*x); // Newton step
return x;
}
int main()
{
float f=2;
float f1 = InvSqrt(f);
float f2 = sqrt(f);
float r = fabs(f1 - f2);
printf("%f %f %f\n", f1, f2, r);
}