Skip to content

Commit

Permalink
util: use ES2015+ Object.is to check negative zero
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
shinnn authored and MylesBorins committed Mar 9, 2017
1 parent e7b7d72 commit e54b433
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,8 @@ function formatValue(ctx, value, recurseTimes) {


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

0 comments on commit e54b433

Please sign in to comment.