Fix mathlib min, max and atan2 behaviour
This commit is contained in:
@@ -269,9 +269,9 @@ public class MathLib extends TwoArgFunction {
|
||||
static class max extends VarArgFunction {
|
||||
@Override
|
||||
public Varargs invoke(Varargs args) {
|
||||
LuaValue m = args.checkvalue(1);
|
||||
LuaValue m = args.checknumber(1);
|
||||
for (int i = 2, n = args.narg(); i <= n; ++i) {
|
||||
LuaValue v = args.checkvalue(i);
|
||||
LuaValue v = args.checknumber(i);
|
||||
if (m.lt_b(v))
|
||||
m = v;
|
||||
}
|
||||
@@ -282,9 +282,9 @@ public class MathLib extends TwoArgFunction {
|
||||
static class min extends VarArgFunction {
|
||||
@Override
|
||||
public Varargs invoke(Varargs args) {
|
||||
LuaValue m = args.checkvalue(1);
|
||||
LuaValue m = args.checknumber(1);
|
||||
for (int i = 2, n = args.narg(); i <= n; ++i) {
|
||||
LuaValue v = args.checkvalue(i);
|
||||
LuaValue v = args.checknumber(i);
|
||||
if (v.lt_b(m))
|
||||
m = v;
|
||||
}
|
||||
|
||||
@@ -96,9 +96,8 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
|
||||
LuaValue math = env.get("math");
|
||||
math.set("acos", new acos());
|
||||
math.set("asin", new asin());
|
||||
LuaValue atan = new atan2();
|
||||
math.set("atan", atan);
|
||||
math.set("atan2", atan);
|
||||
math.set("atan", new atan());
|
||||
math.set("atan2", new atan2());
|
||||
math.set("cosh", new cosh());
|
||||
math.set("exp", new exp());
|
||||
math.set("log", new log());
|
||||
@@ -118,13 +117,20 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
|
||||
protected double call(double d) { return Math.asin(d); }
|
||||
}
|
||||
|
||||
static final class atan2 extends TwoArgFunction {
|
||||
static final class atan extends TwoArgFunction {
|
||||
@Override
|
||||
public LuaValue call(LuaValue x, LuaValue y) {
|
||||
return valueOf(Math.atan2(x.checkdouble(), y.optdouble(1)));
|
||||
}
|
||||
}
|
||||
|
||||
static final class atan2 extends TwoArgFunction {
|
||||
@Override
|
||||
public LuaValue call(LuaValue x, LuaValue y) {
|
||||
return valueOf(Math.atan2(x.checkdouble(), y.checkdouble()));
|
||||
}
|
||||
}
|
||||
|
||||
static final class cosh extends UnaryOp {
|
||||
@Override
|
||||
protected double call(double d) { return Math.cosh(d); }
|
||||
|
||||
Reference in New Issue
Block a user