Skip to content

Commit

Permalink
Add Uint128::checked_pow
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Sep 11, 2021
1 parent 4e94d12 commit 6e14d03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ and this project adheres to
the contract call was executed in.
- cosmwasm-std: New getters `Decimal{,256}::atomics()` and
`Decimal{,256}::decimal_places()`.
- cosmwasm-std: New `Uint128::checked_pow`.

### Changed

Expand Down
7 changes: 7 additions & 0 deletions packages/std/src/math/uint128.rs
Expand Up @@ -76,6 +76,13 @@ impl Uint128 {
.ok_or_else(|| OverflowError::new(OverflowOperation::Mul, self, other))
}

pub fn checked_pow(self, exp: u32) -> Result<Self, OverflowError> {
self.0
.checked_pow(exp)
.map(Self)
.ok_or_else(|| OverflowError::new(OverflowOperation::Pow, self, exp))
}

pub fn checked_div(self, other: Self) -> Result<Self, DivideByZeroError> {
self.0
.checked_div(other.0)
Expand Down

0 comments on commit 6e14d03

Please sign in to comment.