Skip to content

Commit 909f94a

Browse files
committed
#338 [BUGFIX] exponentiatedBy: ensure 0**-n === Infinity for very large n
1 parent f20d7de commit 909f94a

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#### 9.1.1
2+
* 04/12/22
3+
* #338 [BUGFIX] `exponentiatedBy`: ensure `0**-n === Infinity` for very large `n`.
4+
15
#### 9.1.0
26
* 08/08/22
37
* #329 Remove `import` example.
48
* #277 Resolve lint warnings and add number `toString` note.
5-
* Correct `decimalPlaces()` return type in *bignumber.d.ts*.
9+
* Correct `decimalPlaces()` return type in *bignumber.d.ts*.
610
* Add ES module global `crypto` example.
711
* #322 Add `exports` field to *package.json*.
812
* #251 (#308) Amend *bignumber.d.ts* to allow instantiating a BigNumber without `new`.

bignumber.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@
17061706

17071707
// The sign of the result of pow when x is negative depends on the evenness of n.
17081708
// If +n overflows to ±Infinity, the evenness of n would be not be known.
1709-
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
1709+
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
17101710
return m ? y.mod(m) : y;
17111711
}
17121712

@@ -2012,7 +2012,7 @@
20122012
xc = yc;
20132013
yc = t;
20142014
y.s = -y.s;
2015-
}
2015+
}
20162016

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

@@ -2173,7 +2173,7 @@
21732173
i = xcL;
21742174
xcL = ycL;
21752175
ycL = i;
2176-
}
2176+
}
21772177

21782178
// Initialise the result array with zeros.
21792179
for (i = xcL + ycL, zc = []; i--; zc.push(0));
@@ -2299,7 +2299,7 @@
22992299
yc = xc;
23002300
xc = t;
23012301
b = a;
2302-
}
2302+
}
23032303

23042304
// Only start adding at yc.length - 1 as the further digits of xc can be ignored.
23052305
for (a = 0; b;) {
@@ -2590,7 +2590,7 @@
25902590
g1 = g2;
25912591
g2 = i;
25922592
len -= i;
2593-
}
2593+
}
25942594

25952595
if (g1 > 0 && len > 0) {
25962596
i = len % g1 || g1;

bignumber.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ function clone(configObject) {
17031703

17041704
// The sign of the result of pow when x is negative depends on the evenness of n.
17051705
// If +n overflows to ±Infinity, the evenness of n would be not be known.
1706-
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
1706+
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
17071707
return m ? y.mod(m) : y;
17081708
}
17091709

test/methods/exponentiatedBy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Test('exponentiatedBy', function () {
4040
t('NaN', 0, NaN);
4141
t('0', 0, Infinity);
4242
t('Infinity', 0, -Infinity);
43+
t('Infinity', 0, '-123456789012345');
44+
t('Infinity', 0, '-12345678901234567890123456789012345678901234567890');
4345

4446
//-0
4547
t('1', -0, +0);
@@ -51,6 +53,8 @@ Test('exponentiatedBy', function () {
5153
t('NaN', -0, NaN);
5254
t('0', -0, Infinity);
5355
t('Infinity', -0, -Infinity);
56+
t('-Infinity', -0, '-123456789012345');
57+
t('Infinity', -0, '-12345678901234567890123456789012345678901234567890');
5458

5559
// 1
5660
t('1', 1, +0);

0 commit comments

Comments
 (0)