diff --git a/CHANGELOG.md b/CHANGELOG.md index d77e854..ea0b369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ +#### 9.1.1 +* 04/12/22 +* #338 [BUGFIX] `exponentiatedBy`: ensure `0**-n === Infinity` for very large `n`. + #### 9.1.0 * 08/08/22 * #329 Remove `import` example. * #277 Resolve lint warnings and add number `toString` note. -* Correct `decimalPlaces()` return type in *bignumber.d.ts*. +* Correct `decimalPlaces()` return type in *bignumber.d.ts*. * Add ES module global `crypto` example. * #322 Add `exports` field to *package.json*. * #251 (#308) Amend *bignumber.d.ts* to allow instantiating a BigNumber without `new`. diff --git a/bignumber.js b/bignumber.js index c4a96c3..dff3165 100644 --- a/bignumber.js +++ b/bignumber.js @@ -1706,7 +1706,7 @@ // The sign of the result of pow when x is negative depends on the evenness of n. // If +n overflows to ±Infinity, the evenness of n would be not be known. - y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n))); + y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n))); return m ? y.mod(m) : y; } @@ -2012,7 +2012,7 @@ xc = yc; yc = t; y.s = -y.s; - } + } b = (j = yc.length) - (i = xc.length); @@ -2173,7 +2173,7 @@ i = xcL; xcL = ycL; ycL = i; - } + } // Initialise the result array with zeros. for (i = xcL + ycL, zc = []; i--; zc.push(0)); @@ -2299,7 +2299,7 @@ yc = xc; xc = t; b = a; - } + } // Only start adding at yc.length - 1 as the further digits of xc can be ignored. for (a = 0; b;) { @@ -2590,7 +2590,7 @@ g1 = g2; g2 = i; len -= i; - } + } if (g1 > 0 && len > 0) { i = len % g1 || g1; diff --git a/bignumber.mjs b/bignumber.mjs index 445bc70..db229a1 100644 --- a/bignumber.mjs +++ b/bignumber.mjs @@ -1703,7 +1703,7 @@ function clone(configObject) { // The sign of the result of pow when x is negative depends on the evenness of n. // If +n overflows to ±Infinity, the evenness of n would be not be known. - y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n))); + y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n))); return m ? y.mod(m) : y; } diff --git a/test/methods/exponentiatedBy.js b/test/methods/exponentiatedBy.js index 1ec1878..46dfea6 100644 --- a/test/methods/exponentiatedBy.js +++ b/test/methods/exponentiatedBy.js @@ -40,6 +40,8 @@ Test('exponentiatedBy', function () { t('NaN', 0, NaN); t('0', 0, Infinity); t('Infinity', 0, -Infinity); + t('Infinity', 0, '-123456789012345'); + t('Infinity', 0, '-12345678901234567890123456789012345678901234567890'); //-0 t('1', -0, +0); @@ -51,6 +53,8 @@ Test('exponentiatedBy', function () { t('NaN', -0, NaN); t('0', -0, Infinity); t('Infinity', -0, -Infinity); + t('-Infinity', -0, '-123456789012345'); + t('Infinity', -0, '-12345678901234567890123456789012345678901234567890'); // 1 t('1', 1, +0);