summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lobject.js6
1 files changed, 5 insertions, 1 deletions
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);
}
};