Skip to content

Commit b718e45

Browse files
devsnekgibfahn
authored andcommitted
util: fix negative 0 check in inspect
PR-URL: #17507 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent c8220b9 commit b718e45

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/util.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
617617
}
618618

619619
function formatNumber(fn, value) {
620-
// Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0.
621-
// Using a division check is currently faster than `Object.is(value, -0)`
622-
// as of V8 6.1.
623-
if (1 / value === -Infinity)
620+
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
621+
if (Object.is(value, -0))
624622
return fn('-0', 'number');
625623
return fn(`${value}`, 'number');
626624
}

test/parallel/test-util-inspect.js

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ assert.strictEqual(
405405
// test positive/negative zero
406406
assert.strictEqual(util.inspect(0), '0');
407407
assert.strictEqual(util.inspect(-0), '-0');
408+
// edge case from check
409+
assert.strictEqual(util.inspect(-5e-324), '-5e-324');
408410

409411
// test for sparse array
410412
{

0 commit comments

Comments
 (0)