From 4105cebf1ed8ffb074c82cc61a15b7b255e04b9b Mon Sep 17 00:00:00 2001 From: Enyby Date: Mon, 24 Dec 2018 20:37:39 +0200 Subject: [PATCH] Fix math.fmod for int values. --- src/core/org/luaj/vm2/lib/MathLib.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/org/luaj/vm2/lib/MathLib.java b/src/core/org/luaj/vm2/lib/MathLib.java index 29f2022a..74fd28a0 100644 --- a/src/core/org/luaj/vm2/lib/MathLib.java +++ b/src/core/org/luaj/vm2/lib/MathLib.java @@ -163,10 +163,12 @@ public class MathLib extends TwoArgFunction { } } - static final class fmod extends BinaryOp { - protected double call(double x, double y) { - double q = x/y; - return x - y * (q>=0? Math.floor(q): Math.ceil(q)); + static final class fmod extends TwoArgFunction { + public LuaValue call(LuaValue xv, LuaValue yv) { + if (xv.islong() && yv.islong()) { + return valueOf(xv.tolong() % yv.tolong()); + } + return valueOf(xv.checkdouble() % yv.checkdouble()); } } static final class ldexp extends BinaryOp {