diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-18 12:21:07 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-18 12:21:07 +1000 |
commit | 31cbed5d79e18f8375bcaa56c55d1bd7053b1297 (patch) | |
tree | 15830362e7150828ba3da31be81e4a100e634db8 /src/lobject.js | |
parent | 0d4162d076423e92424de8ae507354cf9d165bdc (diff) | |
download | fengari-31cbed5d79e18f8375bcaa56c55d1bd7053b1297.tar.gz fengari-31cbed5d79e18f8375bcaa56c55d1bd7053b1297.tar.bz2 fengari-31cbed5d79e18f8375bcaa56c55d1bd7053b1297.zip |
src/lobject.js: Fix floating point mod operation
Closes #54
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 6 |
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); } }; |