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 <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>
  • Loading branch information
devsnek authored and gibfahn committed Dec 20, 2017
1 parent c8220b9 commit b718e45
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 @@ -617,10 +617,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 @@ -405,6 +405,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 b718e45

Please sign in to comment.