From 31cbed5d79e18f8375bcaa56c55d1bd7053b1297 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 18 May 2017 12:21:07 +1000 Subject: src/lobject.js: Fix floating point mod operation Closes #54 --- src/lobject.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lobject.js b/src/lobject.js index 680e293..3ec04f6 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -545,7 +545,11 @@ const numarith = function(L, op, v1, v2) { case defs.LUA_OPPOW: return Math.pow(v1, v2); case defs.LUA_OPIDIV: return Math.floor(v1 / v2); case defs.LUA_OPUNM: return -v1; - case defs.LUA_OPMOD: return v1 % v2; + case defs.LUA_OPMOD: + let m = v1 % v2; + if ((m*v2) < 0) + m += v2; + return m; default: assert(0); } }; -- cgit v1.2.3-70-g09d2