From 5ddf72290b3035832fcdb4bbbc8f4b10931ebecf Mon Sep 17 00:00:00 2001 From: Shinnosuke Watanabe Date: Mon, 13 Feb 2017 17:15:26 +0900 Subject: [PATCH] util: use ES2015+ Object.is to check negative zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `Object.is` to check whether the value is negative zero or not. Ref: https://github.com/nodejs/node/commit/b3e4fc6a48b97b52bd19de43c76b7082dcab4988 PR-URL: https://github.com/nodejs/node/pull/11332 Reviewed-By: Ben Noordhuis Reviewed-By: Michaƫl Zasso Reviewed-By: Evan Lucas Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Luigi Pinca --- lib/util.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index b16692cccfb..dec2e6b3903 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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'); }