Example #1
0
 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);
 }
Example #2
0
 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;
 }
Example #3
0
 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);
   }
 }
Example #4
0
 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);
   }
 }
Example #5
0
 public static int round(float x) {
   return (int) NativeMath.round(x);
 }
Example #6
0
 public static double floor(double x) {
   return NativeMath.floor(x);
 }
Example #7
0
 public static double cbrt(double x) {
   return x == 0 || !Double.isFinite(x) ? x : NativeMath.pow(x, 1.0 / 3.0);
 }
Example #8
0
 public static double atan(double x) {
   return NativeMath.atan(x);
 }
Example #9
0
 public static float abs(float x) {
   return (float) NativeMath.abs(x);
 }
Example #10
0
 public static double sqrt(double x) {
   return NativeMath.sqrt(x);
 }
Example #11
0
 public static double min(double x, double y) {
   return NativeMath.min(x, y);
 }
Example #12
0
 public static double max(double x, double y) {
   return NativeMath.max(x, y);
 }
Example #13
0
 public static double log1p(double x) {
   return x == 0 ? x : NativeMath.log(x + 1);
 }
Example #14
0
 public static double log10(double x) {
   return NativeMath.log(x) * NativeMath.LOG10E;
 }
Example #15
0
 public static double log(double x) {
   return NativeMath.log(x);
 }
Example #16
0
 public static double hypot(double x, double y) {
   return Double.isInfinite(x) || Double.isInfinite(y)
       ? Double.POSITIVE_INFINITY
       : NativeMath.sqrt(x * x + y * y);
 }
Example #17
0
 public static double sin(double x) {
   return NativeMath.sin(x);
 }
Example #18
0
 public static double sinh(double x) {
   return x == 0 ? x : (NativeMath.exp(x) - NativeMath.exp(-x)) / 2;
 }
Example #19
0
 public static float min(float x, float y) {
   return (float) NativeMath.min(x, y);
 }
Example #20
0
 public static double pow(double x, double exp) {
   return NativeMath.pow(x, exp);
 }
Example #21
0
 public static double random() {
   return NativeMath.random();
 }
Example #22
0
 public static double acos(double x) {
   return NativeMath.acos(x);
 }
Example #23
0
 public static double copySign(double magnitude, double sign) {
   return isNegative(sign) ? -NativeMath.abs(magnitude) : NativeMath.abs(magnitude);
 }
Example #24
0
 public static double atan2(double y, double x) {
   return NativeMath.atan2(y, x);
 }
Example #25
0
 public static double exp(double x) {
   return NativeMath.exp(x);
 }
Example #26
0
 public static double ceil(double x) {
   return NativeMath.ceil(x);
 }
Example #27
0
 public static double expm1(double d) {
   return d == 0 ? d : NativeMath.exp(d) - 1;
 }
Example #28
0
 public static long round(double x) {
   return (long) NativeMath.round(x);
 }
Example #29
0
 public static double cosh(double x) {
   return (NativeMath.exp(x) + NativeMath.exp(-x)) / 2;
 }