Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: fix negative 0 check in inspect #17507

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,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 @@ -417,6 +417,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