-// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL ]
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
package org.ibex.js;
/** The JavaScript Math object */
-class JSMath extends JS {
- private static final JS E = JS.N(java.lang.Math.E);
- private static final JS PI = JS.N(java.lang.Math.PI);
- private static final JS LN10 = JS.N(java.lang.Math.log(10));
- private static final JS LN2 = JS.N(java.lang.Math.log(2));
- private static final JS LOG10E = JS.N(1/java.lang.Math.log(10));
- private static final JS LOG2E = JS.N(1/java.lang.Math.log(2));
- private static final JS SQRT1_2 = JS.N(1/java.lang.Math.sqrt(2));
- private static final JS SQRT2 = JS.N(java.lang.Math.sqrt(2));
+class JSMath extends JS.Immutable {
+ private static final JS.Method METHOD = new JS.Method();
- public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
- switch(nargs) {
+ 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 JS call(JS method, JS[] args) throws JSExn {
+ switch(args.length) {
case 0: {
- //#switch(JS.toString(method))
- case "random": return JS.N(java.lang.Math.random());
+ //#switch(Script.toString(method))
+ case "random": return Script.N(java.lang.Math.random());
//#end
break;
}
case 1: {
- //#switch(JS.toString(method))
- case "ceil": return JS.N((long)java.lang.Math.ceil(toDouble(a0)));
- case "floor": return JS.N((long)java.lang.Math.floor(toDouble(a0)));
- case "round": return JS.N((long)java.lang.Math.round(toDouble(a0)));
- case "abs": return JS.N(java.lang.Math.abs(toDouble(a0)));
- case "sin": return JS.N(java.lang.Math.sin(toDouble(a0)));
- case "cos": return JS.N(java.lang.Math.cos(toDouble(a0)));
- case "tan": return JS.N(java.lang.Math.tan(toDouble(a0)));
- case "asin": return JS.N(java.lang.Math.asin(toDouble(a0)));
- case "acos": return JS.N(java.lang.Math.acos(toDouble(a0)));
- case "atan": return JS.N(java.lang.Math.atan(toDouble(a0)));
- case "sqrt": return JS.N(java.lang.Math.sqrt(toDouble(a0)));
- case "exp": return JS.N(java.lang.Math.exp(toDouble(a0)));
- case "log": return JS.N(java.lang.Math.log(toDouble(a0)));
+ //#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])));
//#end
break;
}
case 2: {
- //#switch(JS.toString(method))
- case "min": return JS.N(java.lang.Math.min(toDouble(a0), toDouble(a1)));
- case "max": return JS.N(java.lang.Math.max(toDouble(a0), toDouble(a1)));
- case "pow": return JS.N(java.lang.Math.pow(toDouble(a0), toDouble(a1)));
- case "atan2": return JS.N(java.lang.Math.atan2(toDouble(a0), toDouble(a1)));
+ //#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])));
//#end
break;
}
}
- return super.callMethod(method, a0, a1, a2, rest, nargs);
+ return super.call(method, args);
}
public JS get(JS key) throws JSExn {
- //#switch(JS.toString(key))
+ //#switch(Script.toString(key))
case "E": return E;
case "LN10": return LN10;
case "LN2": return LN2;