diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-04-14 14:52:58 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-04-14 14:52:58 +0200 |
commit | 71a6b037db832205b54119de0769a48063d42550 (patch) | |
tree | e5278a582e5c61c2a6eb77327210c21192abf9d1 /src | |
parent | c40f6b898cc36a1f6e2359946b524e46982d70f2 (diff) | |
download | fengari-71a6b037db832205b54119de0769a48063d42550.tar.gz fengari-71a6b037db832205b54119de0769a48063d42550.tar.bz2 fengari-71a6b037db832205b54119de0769a48063d42550.zip |
Use Lua's modulo semantic
Diffstat (limited to 'src')
-rw-r--r-- | src/lobject.js | 2 | ||||
-rw-r--r-- | src/lvm.js | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/lobject.js b/src/lobject.js index 710a906..aeaa105 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -540,7 +540,7 @@ const intarith = function(L, op, v1, v2) { case lua.LUA_OPADD: return (v1 + v2); case lua.LUA_OPSUB: return (v1 - v2); case lua.LUA_OPMUL: return (v1 * v2); - case lua.LUA_OPMOD: return (v1 % v2); + case lua.LUA_OPMOD: return (v1 - Math.floor(v1 / v2) * v2); // % semantic on negative numbers is different in js case lua.LUA_OPIDIV: return (v1 / v2); case lua.LUA_OPBAND: return (v1 & v2); case lua.LUA_OPBOR: return (v1 | v2); @@ -281,9 +281,9 @@ const luaV_execute = function(L) { let numberop2 = tonumber(op2); if (op1.ttisinteger() && op2.ttisinteger()) { - L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value % op2.value)); + L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value - Math.floor(op1.value / op2.value) * op2.value)); } else if (numberop1 !== false && numberop2 !== false) { - L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value % op2.value); + L.stack[ra] = new TValue(CT.LUA_TNUMFLT, (numberop1 - Math.floor(numberop1 / numberop2) * numberop2)); } else { ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_MOD); base = ci.u.l.base; |