From a03731592688eeaa585b34b12d5c6cadae0e1598 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Tue, 10 Sep 2024 18:14:55 +0100 Subject: [PATCH] #212 Bugfix: `sqrt` error when Big.strict set `true`. --- big.js | 4 ++-- big.mjs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/big.js b/big.js index 7743ddd..2ffef64 100644 --- a/big.js +++ b/big.js @@ -806,7 +806,7 @@ } // Estimate. - s = Math.sqrt(x + ''); + s = Math.sqrt(+stringify(x, true, true)); // Math.sqrt underflow/overflow? // Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent. @@ -971,7 +971,7 @@ * Return the value of this Big as a primitve number. */ P.toNumber = function () { - var n = Number(stringify(this, true, true)); + var n = +stringify(this, true, true); if (this.constructor.strict === true && !this.eq(n.toString())) { throw Error(NAME + 'Imprecise conversion'); } diff --git a/big.mjs b/big.mjs index 079b743..f89e5e2 100644 --- a/big.mjs +++ b/big.mjs @@ -803,7 +803,7 @@ P.sqrt = function () { } // Estimate. - s = Math.sqrt(x + ''); + s = Math.sqrt(+stringify(x, true, true)); // Math.sqrt underflow/overflow? // Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent. @@ -968,7 +968,7 @@ P[Symbol.for('nodejs.util.inspect.custom')] = P.toJSON = P.toString = function ( * Return the value of this Big as a primitve number. */ P.toNumber = function () { - var n = Number(stringify(this, true, true)); + var n = +stringify(this, true, true); if (this.constructor.strict === true && !this.eq(n.toString())) { throw Error(NAME + 'Imprecise conversion'); }