Skip to content

Commit

Permalink
util: fix negative 0 check in inspect
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
devsnek authored and MylesBorins committed Dec 12, 2017
1 parent 6576382 commit 8383c34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,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');
}
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,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
{
Expand Down

0 comments on commit 8383c34

Please sign in to comment.