From 204ab9fba5a7a1e2e6981c11e0a6c67764332d21 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 10 Apr 2017 13:47:01 +0200 Subject: nan, -inf, inf --- src/lobject.js | 4 ++-- src/lstrlib.js | 8 ++++++-- src/lvm.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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; -- cgit v1.2.3-54-g00ecf