util: fix negative 0 check in inspect

PR-URL: https://github.com/nodejs/node/pull/17507
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Gus Caplan 2017-12-06 15:09:07 -06:00 committed by Anatoli Papirovski
parent e9d1e1265a
commit 86527bd762
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0
2 changed files with 4 additions and 4 deletions

View File

@ -597,10 +597,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
}
function formatNumber(fn, value) {
// Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0.
// Using a division check is currently faster than `Object.is(value, -0)`
// as of V8 6.1.
if (1 / value === -Infinity)
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
if (Object.is(value, -0))
return fn('-0', 'number');
return fn(`${value}`, 'number');
}

View File

@ -417,6 +417,8 @@ assert.strictEqual(
// test positive/negative zero
assert.strictEqual(util.inspect(0), '0');
assert.strictEqual(util.inspect(-0), '-0');
// edge case from check
assert.strictEqual(util.inspect(-5e-324), '-5e-324');
// test for sparse array
{