Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b718e45

Browse filesBrowse files
devsnekgibfahn
authored andcommitted
util: fix negative 0 check in inspect
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>
1 parent c8220b9 commit b718e45
Copy full SHA for b718e45

File tree

Expand file treeCollapse file tree

2 files changed

+4
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-4
lines changed
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+2-4Lines changed: 2 additions & 4 deletions
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
}
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+2Lines changed: 2 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.