Skip to content

Commit

Permalink
[KGA-3] [KGA-122] fix: SSJ pow (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Nov 13, 2024
1 parent 935c223 commit a24ea25
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/utils/src/math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ impl ExponentiationImpl<
> of Exponentiation<T> {
fn pow(self: T, mut exponent: T) -> T {
let zero = Zero::zero();
if exponent.is_zero() {
return One::one();
}
if self.is_zero() {
return zero;
}
Expand Down Expand Up @@ -361,6 +364,7 @@ mod tests {

#[test]
fn test_wrapping_pow() {
assert(0_u256.wrapping_pow(0) == 1, '0^0 should be 1');
assert(5_u256.wrapping_pow(10) == 9765625, '5^10 should be 9765625');
assert(
5_u256
Expand All @@ -376,6 +380,7 @@ mod tests {

#[test]
fn test_pow() {
assert(0_u256.pow(0) == 1, 'n^0 should be 1');
assert(5_u256.pow(10) == 9765625, '5^10 should be 9765625');
assert(5_u256.pow(45) == 28421709430404007434844970703125, '5^45 failed');
assert(123456_u256.pow(0) == 1, 'n^0 should be 1');
Expand Down

0 comments on commit a24ea25

Please sign in to comment.