Skip to content

Commit 8383c34

Browse files
devsnekMylesBorins
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 6576382 commit 8383c34

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
@@ -593,10 +593,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
593593
}
594594

595595
function formatNumber(fn, value) {
596-
// Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0.
597-
// Using a division check is currently faster than `Object.is(value, -0)`
598-
// as of V8 6.1.
599-
if (1 / value === -Infinity)
596+
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
597+
if (Object.is(value, -0))
600598
return fn('-0', 'number');
601599
return fn(`${value}`, 'number');
602600
}

test/parallel/test-util-inspect.js

+2
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ assert.strictEqual(
416416
// test positive/negative zero
417417
assert.strictEqual(util.inspect(0), '0');
418418
assert.strictEqual(util.inspect(-0), '-0');
419+
// edge case from check
420+
assert.strictEqual(util.inspect(-5e-324), '-5e-324');
419421

420422
// test for sparse array
421423
{

0 commit comments

Comments
 (0)