summaryrefslogtreecommitdiff
path: root/src/lstrlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-10 13:47:01 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-10 13:54:58 +0200
commit204ab9fba5a7a1e2e6981c11e0a6c67764332d21 (patch)
tree4976b9295969a7b0a2b4b124710d235771f325e4 /src/lstrlib.js
parent89e4a76a812499cc108bb77fb5c9ae1877123df6 (diff)
downloadfengari-204ab9fba5a7a1e2e6981c11e0a6c67764332d21.tar.gz
fengari-204ab9fba5a7a1e2e6981c11e0a6c67764332d21.tar.bz2
fengari-204ab9fba5a7a1e2e6981c11e0a6c67764332d21.zip
nan, -inf, inf
Diffstat (limited to 'src/lstrlib.js')
-rw-r--r--src/lstrlib.js8
1 files changed, 6 insertions, 2 deletions
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));