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 <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
shinnn authored and italoacasas committed Feb 22, 2017
1 parent 5b5dca9 commit 3bdac54
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 @@ -604,9 +604,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 3bdac54

Please sign in to comment.