diff --git a/decimal.es6.js b/decimal.es6.js index a2fdcc6..7ab6e27 100644 --- a/decimal.es6.js +++ b/decimal.es6.js @@ -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 diff --git a/decimal.js b/decimal.js index d3c1227..768c113 100644 --- a/decimal.js +++ b/decimal.js @@ -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;