static void init(Scriptable scope, boolean sealed) { NativeMath obj = new NativeMath(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "Math", obj, ScriptableObject.DONTENUM); }
public static double rint(double x) { // Floating point has a mantissa with an accuracy of 52 bits so // any number bigger than 2^52 is effectively a finite integer value. // This case also filters out NaN and infinite values. if (NativeMath.abs(x) < (double) (1L << 52)) { double mod2 = x % 2; if ((mod2 == -1.5) || (mod2 == 0.5)) { x = NativeMath.floor(x); } else { x = NativeMath.round(x); } } return x; }
public static double tanh(double x) { if (x == 0.0) { return x; } else if (Double.isInfinite(x)) { return signum(x); } else { double e2x = NativeMath.exp(2 * x); return (e2x - 1) / (e2x + 1); } }
public static double scalb(double d, int scaleFactor) { if (scaleFactor >= 31 || scaleFactor <= -31) { return d * NativeMath.pow(2, scaleFactor); } else if (scaleFactor > 0) { return d * (1 << scaleFactor); } else if (scaleFactor == 0) { return d; } else { return d / (1 << -scaleFactor); } }
public static int round(float x) { return (int) NativeMath.round(x); }
public static double floor(double x) { return NativeMath.floor(x); }
public static double cbrt(double x) { return x == 0 || !Double.isFinite(x) ? x : NativeMath.pow(x, 1.0 / 3.0); }
public static double atan(double x) { return NativeMath.atan(x); }
public static float abs(float x) { return (float) NativeMath.abs(x); }
public static double sqrt(double x) { return NativeMath.sqrt(x); }
public static double min(double x, double y) { return NativeMath.min(x, y); }
public static double max(double x, double y) { return NativeMath.max(x, y); }
public static double log1p(double x) { return x == 0 ? x : NativeMath.log(x + 1); }
public static double log10(double x) { return NativeMath.log(x) * NativeMath.LOG10E; }
public static double log(double x) { return NativeMath.log(x); }
public static double hypot(double x, double y) { return Double.isInfinite(x) || Double.isInfinite(y) ? Double.POSITIVE_INFINITY : NativeMath.sqrt(x * x + y * y); }
public static double sin(double x) { return NativeMath.sin(x); }
public static double sinh(double x) { return x == 0 ? x : (NativeMath.exp(x) - NativeMath.exp(-x)) / 2; }
public static float min(float x, float y) { return (float) NativeMath.min(x, y); }
public static double pow(double x, double exp) { return NativeMath.pow(x, exp); }
public static double random() { return NativeMath.random(); }
public static double acos(double x) { return NativeMath.acos(x); }
public static double copySign(double magnitude, double sign) { return isNegative(sign) ? -NativeMath.abs(magnitude) : NativeMath.abs(magnitude); }
public static double atan2(double y, double x) { return NativeMath.atan2(y, x); }
public static double exp(double x) { return NativeMath.exp(x); }
public static double ceil(double x) { return NativeMath.ceil(x); }
public static double expm1(double d) { return d == 0 ? d : NativeMath.exp(d) - 1; }
public static long round(double x) { return (long) NativeMath.round(x); }
public static double cosh(double x) { return (NativeMath.exp(x) + NativeMath.exp(-x)) / 2; }