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:
parent
e9d1e1265a
commit
86527bd762
@ -597,10 +597,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatNumber(fn, value) {
|
function formatNumber(fn, value) {
|
||||||
// Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0.
|
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
|
||||||
// Using a division check is currently faster than `Object.is(value, -0)`
|
if (Object.is(value, -0))
|
||||||
// as of V8 6.1.
|
|
||||||
if (1 / value === -Infinity)
|
|
||||||
return fn('-0', 'number');
|
return fn('-0', 'number');
|
||||||
return fn(`${value}`, 'number');
|
return fn(`${value}`, 'number');
|
||||||
}
|
}
|
||||||
|
@ -417,6 +417,8 @@ assert.strictEqual(
|
|||||||
// test positive/negative zero
|
// test positive/negative zero
|
||||||
assert.strictEqual(util.inspect(0), '0');
|
assert.strictEqual(util.inspect(0), '0');
|
||||||
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
|
// test for sparse array
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user