Skip to content

Commit a037315

Browse files
committed
#212 Bugfix: sqrt error when Big.strict set true.
1 parent 9c6c959 commit a037315

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

big.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@
806806
}
807807

808808
// Estimate.
809-
s = Math.sqrt(x + '');
809+
s = Math.sqrt(+stringify(x, true, true));
810810

811811
// Math.sqrt underflow/overflow?
812812
// Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent.
@@ -971,7 +971,7 @@
971971
* Return the value of this Big as a primitve number.
972972
*/
973973
P.toNumber = function () {
974-
var n = Number(stringify(this, true, true));
974+
var n = +stringify(this, true, true);
975975
if (this.constructor.strict === true && !this.eq(n.toString())) {
976976
throw Error(NAME + 'Imprecise conversion');
977977
}

big.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ P.sqrt = function () {
803803
}
804804

805805
// Estimate.
806-
s = Math.sqrt(x + '');
806+
s = Math.sqrt(+stringify(x, true, true));
807807

808808
// Math.sqrt underflow/overflow?
809809
// 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 (
968968
* Return the value of this Big as a primitve number.
969969
*/
970970
P.toNumber = function () {
971-
var n = Number(stringify(this, true, true));
971+
var n = +stringify(this, true, true);
972972
if (this.constructor.strict === true && !this.eq(n.toString())) {
973973
throw Error(NAME + 'Imprecise conversion');
974974
}

0 commit comments

Comments
 (0)