/* explain https://www.youtube.com/watch?v=p8u_k2LIZyo */ #include float Q_rsqrt(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); printf("i = %lu\n", i); y = *( float *) &i; printf("y = %f\n", y); y = y * (threehalfs - (x2*y*y)); return y; } int main() { float n = 5.0; float f = Q_rsqrt(n); printf("1/sqrt(%f) = %f", n, f); return 0; }