From 19ac17bf2246250b9e0c7dae521ae0ac9d4fd43b Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 28 Oct 2021 09:05:19 +0200 Subject: [PATCH] fix: Always return matching signed/unsigned zeroes, fixes #72 --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8adb03a..e55683c 100644 --- a/index.js +++ b/index.js @@ -236,7 +236,7 @@ function fromString(str, unsigned, radix) { if (str.length === 0) throw Error('empty string'); if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return ZERO; + return unsigned ? UZERO : ZERO; if (typeof unsigned === 'number') { // For goog.math.long compatibility radix = unsigned, @@ -878,7 +878,7 @@ LongPrototype.sub = LongPrototype.subtract; */ LongPrototype.multiply = function multiply(multiplier) { if (this.isZero()) - return ZERO; + return this; if (!isLong(multiplier)) multiplier = fromValue(multiplier); @@ -892,7 +892,7 @@ LongPrototype.multiply = function multiply(multiplier) { } if (multiplier.isZero()) - return ZERO; + return this.unsigned ? UZERO : ZERO; if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO; if (multiplier.eq(MIN_VALUE))