improve invSqrt formatting

Co-authored-by: solonovamax <solonovamax@12oclockpoint.com>

what the fuck?
This commit is contained in:
Zoë Gidiere 2023-11-08 21:20:01 -07:00
parent dd7bebb27f
commit 0df940d688

View File

@ -60,12 +60,14 @@ public final class MathUtil {
} }
public static double invSqrt(double x) { public static double invSqrt(double x) {
double xhalf = 0.5d * x; double halfX = 0.5d * x;
long i = Double.doubleToLongBits(x); long i = Double.doubleToLongBits(x); // evil floating point bit level hacking
i = 0x5fe6ec85e7de30daL - (i >> 1); i = 0x5FE6EC85E7DE30DAL - (i >> 1); // what the fuck?
x = Double.longBitsToDouble(i); double y = Double.longBitsToDouble(i);
x *= (1.5d - xhalf * x * x); y *= (1.5d - halfX * y * y); // 1st newtonian iteration
return x; // y *= (1.5d - halfX * y * y); // 2nd newtonian iteration, this can be removed
return y;
} }
/** /**