Skip to content

Instantly share code, notes, and snippets.

@bboston7
Created January 16, 2014 06:59
Show Gist options
  • Save bboston7/8450884 to your computer and use it in GitHub Desktop.
Save bboston7/8450884 to your computer and use it in GitHub Desktop.
public class fisr {
public static void main(String[] args) {
System.out.println(invSqrt(Float.parseFloat(args[0])));
}
public static float invSqrt(float number) {
int i;
float x2, y;
float threehalfs = 1.5F;
x2 = number * 0.5F;
i = Float.floatToIntBits(number);
i = 0x5f3759df - (i >> 1);
y = Float.intBitsToFloat(i);
y = y * (threehalfs - (x2* y * y));
return y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment