Skip to content

Commit 5ddf722

Browse files
shinnnjasnell
authored andcommitted
util: use ES2015+ Object.is to check negative zero
Use `Object.is` to check whether the value is negative zero or not. Ref: b3e4fc6 PR-URL: #11332 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 25e803e commit 5ddf722

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

lib/util.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,8 @@ function formatValue(ctx, value, recurseTimes) {
561561

562562

563563
function formatNumber(ctx, value) {
564-
// Format -0 as '-0'. Strict equality won't distinguish 0 from -0,
565-
// so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 .
566-
if (value === 0 && 1 / value < 0)
564+
// Format -0 as '-0'. Strict equality won't distinguish 0 from -0.
565+
if (Object.is(value, -0))
567566
return ctx.stylize('-0', 'number');
568567
return ctx.stylize('' + value, 'number');
569568
}

0 commit comments

Comments
 (0)