-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Pow
trait and implementations for base numeric types and usize
.
#6694
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ArielElp and @gilbens-starkware)
2cc205f
to
a0bfbc4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @Arcticae, @ArielElp, @Draggu, @gilbens-starkware, @mkaput, and @piotmag769)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Arcticae, @ArielElp, @Draggu, @mkaput, and @orizi)
corelib/src/num/traits/ops/pow.cairo
line 27 at r2 (raw file):
} else { tail_result * self }
Consider changing to an iterative implementation, it is a bit more readable.
And if not, make exp
and self
immutable.
Suggestion:
let mut res = core::num::traits::One::one();
let mut cur_multiplier = self;
while exp != 0 {
let (exp, rem) = DivRem::div_rem(exp,2);
if rem == 1 {
res *= cur_multiplier;
}
cur_multiplier = cur_multiplier * cur_multiplier;
}
a0bfbc4
to
26b2108
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @Arcticae, @ArielElp, @Draggu, @gilbens-starkware, @integraledelebesgue, @mkaput, and @TomerStarkware)
corelib/src/num/traits/ops/pow.cairo
line 27 at r2 (raw file):
Previously, gilbens-starkware (Gil Ben-Shachar) wrote…
Consider changing to an iterative implementation, it is a bit more readable.
And if not, makeexp
andself
immutable.
that was my original implementation - but this solution overflows in cases when no overflow may occur.
(because of the squaring happening at the end of the loop).
mut
removed.
…ze`.