Bugfix: #57 Powers of -1 for integers over Number.MAX_SAFE_INTEGER

pull/73/head
Michael Mclaughlin 7 years ago
parent 3566299686
commit 4d05267ba8

@ -2281,6 +2281,11 @@ P.toPower = P.pow = function (y) {
// Result is negative if x is negative and the last digit of integer y is odd.
sign = sign < 0 && y.d[Math.max(e, k)] & 1 ? -1 : 1;
if (x.eq(-1)) {
x.s = sign;
return x;
}
// Estimate result exponent.
// x^y = 10^e, where e = y * log10(x)
// log10(x) = log10(x_significand) + x_exponent

@ -2283,11 +2283,17 @@
// Result is negative if x is negative and the last digit of integer y is odd.
sign = sign < 0 && y.d[Math.max(e, k)] & 1 ? -1 : 1;
if (x.eq(-1)) {
x.s = sign;
return x;
}
// Estimate result exponent.
// x^y = 10^e, where e = y * log10(x)
// log10(x) = log10(x_significand) + x_exponent
// log10(x_significand) = ln(x_significand) / ln(10)
k = mathpow(+x, yn);
e = k == 0 || !isFinite(k)
? mathfloor(yn * (Math.log('0.' + digitsToString(x.d)) / Math.LN10 + x.e + 1))
: new Ctor(k + '').e;

Loading…
Cancel
Save