From f4dd062a3f87e0876296cc0d7ed449a530a616b3 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Wed, 6 Dec 2017 15:09:07 -0600 Subject: [PATCH] util: fix negative 0 check in inspect --- lib/util.js | 6 ++---- test/parallel/test-util-inspect.js | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index da8d1f0f9b7169..7eae9a99069d2c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -597,10 +597,8 @@ function formatValue(ctx, value, recurseTimes, ln) { } function formatNumber(fn, value) { - // Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0. - // Using a division check is currently faster than `Object.is(value, -0)` - // as of V8 6.1. - if (1 / value === -Infinity) + // Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0. + if (Object.is(value, -0)) return fn('-0', 'number'); return fn(`${value}`, 'number'); } diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index f522abf7c29afd..05eec8cfcf0333 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -417,6 +417,8 @@ assert.strictEqual( // test positive/negative zero assert.strictEqual(util.inspect(0), '0'); assert.strictEqual(util.inspect(-0), '-0'); +// edge case from check +assert.strictEqual(util.inspect(-5e-324), '-5e-324'); // test for sparse array {