From b718e458069a130bea0cd3a7109811d0d073e8ff 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 PR-URL: https://github.com/nodejs/node/pull/17507 Reviewed-By: Refael Ackermann Reviewed-By: Anatoli Papirovski Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Khaidi Chu Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen --- 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 7809cfb7d4109c..9cd5e11719255d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -617,10 +617,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 722ae7d4bd9723..ef4de121bb35f7 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -405,6 +405,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 {