aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-26 09:02:43 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-26 11:41:21 +0200
commitfc482dac2bd84df0bb82216b9036b25a2914474c (patch)
tree8d01005b480161c505626b96455457349a347a47 /src
parente2d9007d484641a3c3dffc325999fe509de1422a (diff)
downloadfengari-fc482dac2bd84df0bb82216b9036b25a2914474c.tar.gz
fengari-fc482dac2bd84df0bb82216b9036b25a2914474c.tar.bz2
fengari-fc482dac2bd84df0bb82216b9036b25a2914474c.zip
math.huge is Number.Infinity
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.js11
-rw-r--r--src/lmathlib.js2
2 files changed, 10 insertions, 3 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 3921519..a70e5d0 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -362,20 +362,27 @@ const luaL_tolstring = function(L, idx) {
luaL_error(L, lua.to_luastring("'__tostring' must return a string", true));
} else {
switch(lua.lua_type(L, idx)) {
- case lua.LUA_TNUMBER:
+ case lua.LUA_TNUMBER: {
if (lua.lua_isinteger(L, idx))
lua.lua_pushstring(L, lua.to_luastring(lua.lua_tointeger(L, idx).toString()));
else {
let n = lua.lua_tonumber(L, idx);
let a = Math.abs(n);
let s;
- if (a > 100000000000000 || a < 0.0001)
+ if (Object.is(n, Infinity))
+ s = 'inf';
+ else if (Object.is(n, -Infinity))
+ s = '-inf';
+ else if (Number.isNaN(n))
+ s = 'nan';
+ else if (a >= 100000000000000 || a < 0.0001)
s = n.toExponential();
else
s = n.toPrecision(16).replace(/(\.[0-9][1-9]*)0+$/, "$1");
lua.lua_pushstring(L, lua.to_luastring(s));
}
break;
+ }
case lua.LUA_TSTRING:
lua.lua_pushvalue(L, idx);
break;
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 49a1abe..7d3a082 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -259,7 +259,7 @@ const luaopen_math = function(L) {
lauxlib.luaL_newlib(L, mathlib);
lua.lua_pushnumber(L, Math.PI);
lua.lua_setfield(L, -2, lua.to_luastring("pi", true));
- lua.lua_pushnumber(L, Number.MAX_VALUE);
+ lua.lua_pushnumber(L, Infinity);
lua.lua_setfield(L, -2, lua.to_luastring("huge", true));
lua.lua_pushinteger(L, llimit.MAX_INT);
lua.lua_setfield(L, -2, lua.to_luastring("maxinteger", true));