Skip to content

Commit

Permalink
#338 [BUGFIX] exponentiatedBy: ensure 0**-n === Infinity for very…
Browse files Browse the repository at this point in the history
… large `n`
  • Loading branch information
MikeMcl committed Dec 4, 2022
1 parent f20d7de commit 909f94a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
10 changes: 5 additions & 5 deletions bignumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -2012,7 +2012,7 @@
xc = yc;
yc = t;
y.s = -y.s;
}
}

b = (j = yc.length) - (i = xc.length);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;) {
Expand Down Expand Up @@ -2590,7 +2590,7 @@
g1 = g2;
g2 = i;
len -= i;
}
}

if (g1 > 0 && len > 0) {
i = len % g1 || g1;
Expand Down
2 changes: 1 addition & 1 deletion bignumber.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions test/methods/exponentiatedBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 909f94a

Please sign in to comment.