Skip to content
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

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

orizi
Copy link
Collaborator

@orizi orizi commented Nov 19, 2024

…ze`.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArielElp and @gilbens-starkware)

Copy link
Collaborator

@TomerStarkware TomerStarkware left a 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Arcticae, @ArielElp, @Draggu, @gilbens-starkware, @mkaput, and @piotmag769)

@piotmag769 piotmag769 removed their request for review November 19, 2024 13:09
Copy link
Contributor

@gilbens-starkware gilbens-starkware left a 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; 
            }

Copy link
Collaborator Author

@orizi orizi left a 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, make exp and self 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.

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 4 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Arcticae, @ArielElp, @Draggu, @integraledelebesgue, and @mkaput)

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Arcticae, @ArielElp, @Draggu, and @integraledelebesgue)

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Arcticae, @ArielElp, @Draggu, and @integraledelebesgue)

@orizi orizi added this pull request to the merge queue Nov 20, 2024
Merged via the queue into main with commit 31658cf Nov 20, 2024
48 checks passed
@orizi orizi deleted the orizi/pow-impl branch November 20, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants