From 92cee0812de7c7164102f2c1c553f120da51b418 Mon Sep 17 00:00:00 2001 From: Enyby Date: Sun, 23 Dec 2018 17:06:34 +0200 Subject: [PATCH] Fix JSE math.log for second arg. --- src/jse/org/luaj/vm2/lib/jse/JseMathLib.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java b/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java index fde2f257..87f133a1 100644 --- a/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java +++ b/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java @@ -98,7 +98,14 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib { } static final class cosh extends UnaryOp { protected double call(double d) { return Math.cosh(d); } } static final class exp extends UnaryOp { protected double call(double d) { return Math.exp(d); } } - static final class log extends UnaryOp { protected double call(double d) { return Math.log(d); } } + static final class log extends TwoArgFunction { + public LuaValue call(LuaValue x, LuaValue base) { + double nat = Math.log(x.checkdouble()); + double b = base.optdouble(Math.E); + if (b != Math.E) nat /= Math.log(b); + return valueOf(nat); + } + } static final class pow extends BinaryOp { protected double call(double x, double y) { return Math.pow(x, y); } } static final class sinh extends UnaryOp { protected double call(double d) { return Math.sinh(d); } } static final class tanh extends UnaryOp { protected double call(double d) { return Math.tanh(d); } }