summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-10 13:20:08 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-10 13:20:08 +0200
commit89e4a76a812499cc108bb77fb5c9ae1877123df6 (patch)
tree0e9e83066e7baaab2a63b442d559745a68f701b7
parent8bbc810540cfed397527d716b822511efa4a2723 (diff)
downloadfengari-89e4a76a812499cc108bb77fb5c9ae1877123df6.tar.gz
fengari-89e4a76a812499cc108bb77fb5c9ae1877123df6.tar.bz2
fengari-89e4a76a812499cc108bb77fb5c9ae1877123df6.zip
Handle -0
-rw-r--r--src/lstrlib.js5
-rw-r--r--tests/single.lua5
2 files changed, 6 insertions, 4 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 81b754d..f4f254f 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -106,7 +106,10 @@ const num2straux = function(x) {
return sprintf(luaconf.LUA_NUMBER_FMT, x).split('').map(e => e.charCodeAt(0));
else if (x === 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */
- return sprintf(luaconf.LUA_NUMBER_FMT + "x0p+0", x).split('').map(e => e.charCodeAt(0));
+ let zero = sprintf(luaconf.LUA_NUMBER_FMT + "x0p+0", x).split('').map(e => e.charCodeAt(0));
+ if (Object.is(x, -0))
+ return [char['-']].concat(zero);
+ return zero;
} else {
let fe = lobject.frexp(x); /* 'x' fraction and exponent */
let m = fe[0];
diff --git a/tests/single.lua b/tests/single.lua
index 6fdce5c..c770d22 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -1,4 +1,4 @@
- -- $Id: strings.lua,v 1.86 2016/11/07 13:11:28 roberto Exp roberto $
+-- $Id: strings.lua,v 1.86 2016/11/07 13:11:28 roberto Exp roberto $
-- See Copyright Notice in file all.lua
print('testing strings and string library')
@@ -269,8 +269,7 @@ do print("testing 'format %a %A'")
end
assert(string.find(string.format("%A", 0.0), "^0X0%.?0?P%+?0$"))
- -- print(string.format("%a", -0.0))
- -- assert(string.find(string.format("%a", -0.0), "^%-0x0%.?0?p%+?0$"))
+ assert(string.find(string.format("%a", -0.0), "^%-0x0%.?0?p%+?0$"))
-- if not _port then -- test inf, -inf, NaN, and -0.0
-- assert(string.find(string.format("%a", 1/0), "^inf"))