Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

[KGA-3] [KGA-122] fix: SSJ pow #1579

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cairo/kakarot-ssj/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 @@ -367,6 +370,7 @@ mod tests {

#[test]
fn test_wrapping_pow() {
assert(0_u256.wrapping_pow(0) == 1, '0^0 should be 1');
Copy link
Collaborator

@obatirou obatirou Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the assert_eq! macro ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason I did as the otherlines in the test. It could be moved to use assert ea

assert(5_u256.wrapping_pow(10) == 9765625, '5^10 should be 9765625');
assert(
5_u256
Expand All @@ -382,6 +386,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
Loading