From a24ea25beffaa8f88dbeb87cdc629d3257d869bb Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Wed, 13 Nov 2024 05:51:54 +0100 Subject: [PATCH] [KGA-3] [KGA-122] fix: SSJ pow (#1022) --- crates/utils/src/math.cairo | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/utils/src/math.cairo b/crates/utils/src/math.cairo index 6e77fdbc9..687fef72a 100644 --- a/crates/utils/src/math.cairo +++ b/crates/utils/src/math.cairo @@ -38,6 +38,9 @@ impl ExponentiationImpl< > of Exponentiation { 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; } @@ -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 @@ -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');