From 4d9579c35241b53ae302be2cd07d72f0e60de964 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 The original code https://github.com/nodejs/node/commit/b3e4fc6a48b97b52bd19de43c76b7082dcab4988 is written in 2013. Today we can use more simple way `Object.is`, which was introduced in ECMAScript 6, to check whether the value is negative zero or not. --- lib/util.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index 003b5e5b54073b..42861aaa5ae8aa 100644 --- a/lib/util.js +++ b/lib/util.js @@ -602,9 +602,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'); }