Skip to content

Commit

Permalink
#212 Bugfix: sqrt error when Big.strict set true.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcl committed Sep 10, 2024
1 parent 9c6c959 commit a037315
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions big.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions big.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit a037315

Please sign in to comment.