From 44779c34305ddc5aa7bf271851f916c6680cdb44 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 01:15:28 +1000 Subject: Use Math.imul when multiplying integers --- src/lobject.js | 2 +- src/lvm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lobject.js b/src/lobject.js index 5d3a984..6ba225d 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -525,7 +525,7 @@ const intarith = function(L, op, v1, v2) { switch (op) { case defs.LUA_OPADD: return (v1 + v2)|0; case defs.LUA_OPSUB: return (v1 - v2)|0; - case defs.LUA_OPMUL: return (v1 * v2)|0; + case defs.LUA_OPMUL: return Math.imul(v1, v2); case defs.LUA_OPMOD: return lvm.luaV_mod(L, v1, v2); case defs.LUA_OPIDIV: return lvm.luaV_div(L, v1, v2); case defs.LUA_OPBAND: return (v1 & v2); diff --git a/src/lvm.js b/src/lvm.js index 3cf406a..e350578 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -242,7 +242,7 @@ const luaV_execute = function(L) { let numberop2 = tonumber(op2); if (op1.ttisinteger() && op2.ttisinteger()) { - L.stack[ra] = new lobject.TValue(CT.LUA_TNUMINT, (op1.value * op2.value)|0); + L.stack[ra] = new lobject.TValue(CT.LUA_TNUMINT, Math.imul(op1.value, op2.value)); } else if (numberop1 !== false && numberop2 !== false) { L.stack[ra] = new lobject.TValue(CT.LUA_TNUMFLT, numberop1 * numberop2); } else { -- cgit v1.2.3-70-g09d2