From e54b433c8d4ec310b2d08d2880b4b8c9faf296ca 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 95c69248e07..3a5a3d06533 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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'); }