Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Oct 11, 2023
1 parent e367ec0 commit 2597db5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 22 additions & 2 deletions crates/utils/src/math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,33 @@ trait Exponentiation<T> {
}

impl ExponentiationImpl<
T, +Zero<T>, +One<T>, +Add<T>, +Sub<T>, +Mul<T>, +Div<T>, +BitAnd<T>, +PartialOrd<T>, +PartialEq<T>, +Copy<T>, +Drop<T>
T,
+Zero<T>,
+One<T>,
+Add<T>,
+Sub<T>,
+Mul<T>,
+Div<T>,
+BitAnd<T>,
+PartialOrd<T>,
+PartialEq<T>,
+Copy<T>,
+Drop<T>
> of Exponentiation<T> {
fn pow(self: T, mut exponent: T) -> T {
if self.is_zero() {
return Zero::zero();
}
let ten = One::one() + One::one() + One::one() + One::one() + One::one() + One::one() + One::one() + One::one() + One::one() + One::one();
let ten = One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one()
+ One::one();
if exponent > ten {
self.fast_pow(exponent)
} else {
Expand Down
8 changes: 7 additions & 1 deletion crates/utils/src/tests/test_math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ fn test_wrapping_slow_pow_runs_out_of_gas() {
#[test]
#[available_gas(20000000)]
fn test_wrapping_fast_pow() {
assert(3_u256.wrapping_fast_pow(3_u256.wrapping_fast_pow(10)) == 6701808933569337837891967767170127839253608180143676463326689955522159283811, '3^(3^10) failed');
assert(
3_u256
.wrapping_fast_pow(
3_u256.wrapping_fast_pow(10)
) == 6701808933569337837891967767170127839253608180143676463326689955522159283811,
'3^(3^10) failed'
);
}

#[test]
Expand Down

0 comments on commit 2597db5

Please sign in to comment.