util: use ES2015+ Object.is to check negative zero

Use `Object.is` to check whether the value is negative zero or not.

Ref: b3e4fc6a48
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Shinnosuke Watanabe 2017-02-13 17:15:26 +09:00 committed by James M Snell
parent 25e803ebd0
commit 5ddf72290b

View File

@ -561,9 +561,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');
}