aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lobject.js4
-rw-r--r--src/lstrlib.js8
-rw-r--r--src/lvm.js2
3 files changed, 9 insertions, 5 deletions
diff --git a/src/lobject.js b/src/lobject.js
index b2cffe3..66a0dcb 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -556,8 +556,8 @@ const intarith = function(L, op, v1, v2) {
case lua.LUA_OPBXOR: return (v1 ^ v2);
case lua.LUA_OPSHL: return (v1 << v2);
case lua.LUA_OPSHR: return (v1 >> v2);
- case lua.LUA_OPUNM: return (-v1);
- case lua.LUA_OPBNOT: return (~v1);
+ case lua.LUA_OPUNM: return (0 - v1);
+ case lua.LUA_OPBNOT: return (~0 ^ v1);
}
};
diff --git a/src/lstrlib.js b/src/lstrlib.js
index f4f254f..73fc068 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -102,8 +102,12 @@ const adddigit = function(buff, n, x) {
const num2straux = function(x) {
let buff = [];
/* if 'inf' or 'NaN', format it like '%g' */
- if (x === Infinity || isNaN(x))
- return sprintf(luaconf.LUA_NUMBER_FMT, x).split('').map(e => e.charCodeAt(0));
+ if (Object.is(x, Infinity))
+ return lua.to_luastring('inf');
+ else if (Object.is(x, -Infinity))
+ return lua.to_luastring('-inf');
+ else if (Number.isNaN(x))
+ return lua.to_luastring('nan');
else if (x === 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */
let zero = sprintf(luaconf.LUA_NUMBER_FMT + "x0p+0", x).split('').map(e => e.charCodeAt(0));
diff --git a/src/lvm.js b/src/lvm.js
index 4786da4..300e622 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -301,7 +301,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
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 / numberop2);
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_DIV);
base = ci.u.l.base;