X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSMath.java;h=e69f4509f6f44d972eda38f84f8d06e0992b88b8;hb=aaf060ff38871512d80f1bbf04a6596648b284c7;hp=a0edb1ab104917acc567cfdb5353ac9e63e8772e;hpb=361d18aff8f32e60fb8b6c5c52744a9f1e9890be;p=org.ibex.js.git diff --git a/src/org/ibex/js/JSMath.java b/src/org/ibex/js/JSMath.java index a0edb1a..e69f450 100644 --- a/src/org/ibex/js/JSMath.java +++ b/src/org/ibex/js/JSMath.java @@ -5,48 +5,50 @@ package org.ibex.js; /** The JavaScript Math object */ -class JSMath extends JS { - private static final JS E = Script.N(java.lang.Math.E); - private static final JS PI = Script.N(java.lang.Math.PI); - private static final JS LN10 = Script.N(java.lang.Math.log(10)); - private static final JS LN2 = Script.N(java.lang.Math.log(2)); - private static final JS LOG10E = Script.N(1/java.lang.Math.log(10)); - private static final JS LOG2E = Script.N(1/java.lang.Math.log(2)); - private static final JS SQRT1_2 = Script.N(1/java.lang.Math.sqrt(2)); - private static final JS SQRT2 = Script.N(java.lang.Math.sqrt(2)); +public class JSMath extends JS.Immutable { + private static final JS.Method METHOD = new JS.Method(); - public JS callMethod(JS method, JS[] args) throws JSExn { + private static final JS E = JSU.N(java.lang.Math.E); + private static final JS PI = JSU.N(java.lang.Math.PI); + private static final JS LN10 = JSU.N(java.lang.Math.log(10)); + private static final JS LN2 = JSU.N(java.lang.Math.log(2)); + private static final JS LOG10E = JSU.N(1/java.lang.Math.log(10)); + private static final JS LOG2E = JSU.N(1/java.lang.Math.log(2)); + private static final JS SQRT1_2 = JSU.N(1/java.lang.Math.sqrt(2)); + private static final JS SQRT2 = JSU.N(java.lang.Math.sqrt(2)); + + public JS call(JS method, JS[] args) throws JSExn { switch(args.length) { case 0: { - //#switch(Script.toString(method)) - case "random": return Script.N(java.lang.Math.random()); + //#switch(JSU.toString(method)) + case "random": return JSU.N(java.lang.Math.random()); //#end break; } case 1: { - //#switch(Script.toString(method)) - case "ceil": return Script.N((long)java.lang.Math.ceil(Script.toDouble(args[0]))); - case "floor": return Script.N((long)java.lang.Math.floor(Script.toDouble(args[0]))); - case "round": return Script.N((long)java.lang.Math.round(Script.toDouble(args[0]))); - case "abs": return Script.N(java.lang.Math.abs(Script.toDouble(args[0]))); - case "sin": return Script.N(java.lang.Math.sin(Script.toDouble(args[0]))); - case "cos": return Script.N(java.lang.Math.cos(Script.toDouble(args[0]))); - case "tan": return Script.N(java.lang.Math.tan(Script.toDouble(args[0]))); - case "asin": return Script.N(java.lang.Math.asin(Script.toDouble(args[0]))); - case "acos": return Script.N(java.lang.Math.acos(Script.toDouble(args[0]))); - case "atan": return Script.N(java.lang.Math.atan(Script.toDouble(args[0]))); - case "sqrt": return Script.N(java.lang.Math.sqrt(Script.toDouble(args[0]))); - case "exp": return Script.N(java.lang.Math.exp(Script.toDouble(args[0]))); - case "log": return Script.N(java.lang.Math.log(Script.toDouble(args[0]))); + //#switch(JSU.toString(method)) + case "ceil": return JSU.N((long)java.lang.Math.ceil(JSU.toDouble(args[0]))); + case "floor": return JSU.N((long)java.lang.Math.floor(JSU.toDouble(args[0]))); + case "round": return JSU.N((long)java.lang.Math.round(JSU.toDouble(args[0]))); + case "abs": return JSU.N(java.lang.Math.abs(JSU.toDouble(args[0]))); + case "sin": return JSU.N(java.lang.Math.sin(JSU.toDouble(args[0]))); + case "cos": return JSU.N(java.lang.Math.cos(JSU.toDouble(args[0]))); + case "tan": return JSU.N(java.lang.Math.tan(JSU.toDouble(args[0]))); + case "asin": return JSU.N(java.lang.Math.asin(JSU.toDouble(args[0]))); + case "acos": return JSU.N(java.lang.Math.acos(JSU.toDouble(args[0]))); + case "atan": return JSU.N(java.lang.Math.atan(JSU.toDouble(args[0]))); + case "sqrt": return JSU.N(java.lang.Math.sqrt(JSU.toDouble(args[0]))); + case "exp": return JSU.N(java.lang.Math.exp(JSU.toDouble(args[0]))); + case "log": return JSU.N(java.lang.Math.log(JSU.toDouble(args[0]))); //#end break; } case 2: { - //#switch(Script.toString(method)) - case "min": return Script.N(java.lang.Math.min(Script.toDouble(args[0]), Script.toDouble(args[1]))); - case "max": return Script.N(java.lang.Math.max(Script.toDouble(args[0]), Script.toDouble(args[1]))); - case "pow": return Script.N(java.lang.Math.pow(Script.toDouble(args[0]), Script.toDouble(args[1]))); - case "atan2": return Script.N(java.lang.Math.atan2(Script.toDouble(args[0]), Script.toDouble(args[1]))); + //#switch(JSU.toString(method)) + case "min": return JSU.N(java.lang.Math.min(JSU.toDouble(args[0]), JSU.toDouble(args[1]))); + case "max": return JSU.N(java.lang.Math.max(JSU.toDouble(args[0]), JSU.toDouble(args[1]))); + case "pow": return JSU.N(java.lang.Math.pow(JSU.toDouble(args[0]), JSU.toDouble(args[1]))); + case "atan2": return JSU.N(java.lang.Math.atan2(JSU.toDouble(args[0]), JSU.toDouble(args[1]))); //#end break; } @@ -55,7 +57,7 @@ class JSMath extends JS { } public JS get(JS key) throws JSExn { - //#switch(Script.toString(key)) + //#switch(JSU.toString(key)) case "E": return E; case "LN10": return LN10; case "LN2": return LN2;