Fast inverse square root

Fast inverse square root can be used to calculate the dx and dy for an object that moves in a straight line. The code is in Java.

float inverseSqrt(float x) 
    float half = 0.5f * x;
    int i = Float.floatToIntBits(x);
    i = 0x5f3759df - (i >> 1);
    x = Float.intBitsToFloat(i);
    x = x * (1.5f - half * x * x);
    return x;
This entry was posted in Useful Code. Bookmark the permalink.