Skip to content

Commit

Permalink
Prevent negative exponents in BigNumber (#925).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 5, 2020
1 parent 0fd9aa5 commit 84e253f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/bignumber/src.ts/bignumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export class BigNumber implements Hexable {
}

pow(other: BigNumberish): BigNumber {
return toBigNumber(toBN(this).pow(toBN(other)));
const value = toBN(other);
if (value.isNeg()) {
throwFault("cannot raise to negative values", "pow");
}
return toBigNumber(toBN(this).pow(value));
}

and(other: BigNumberish): BigNumber {
Expand Down

0 comments on commit 84e253f

Please sign in to comment.