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

UintXX:full_mul consistency #1433

Closed
webmaster128 opened this issue Sep 21, 2022 · 0 comments · Fixed by #1874
Closed

UintXX:full_mul consistency #1433

webmaster128 opened this issue Sep 21, 2022 · 0 comments · Fixed by #1874
Labels
Breaking (contracts) Compile-time breaking contracts
Milestone

Comments

@webmaster128
Copy link
Member

Uint{64, 128, 256}::full_mul should all take Into<Self> as the right hand side. The reason is that mixed type arthmetic operations are discouraged. When we get Uint64*Uint64 -> Uint128, Uint128*Uint128 -> Uint256 and Uint256*Uint256 -> Uint512 where * denotes the full multipleciation operation. Keeping Into<Self> instead of just Self makes it convenient to work with and non-breaking in the vast majority of cases.

Then we can have pretty much the same implementation for all 3 cases:

    pub fn full_mul(self, rhs: impl Into<Self>) -> Uint128 {
        let a = Uint128::from(self);
        let b = Uint128::from(rhs.into());
        a.checked_mul(b).unwrap()
    }
@webmaster128 webmaster128 added the Breaking (contracts) Compile-time breaking contracts label Sep 21, 2022
@webmaster128 webmaster128 added this to the 2.0.0 milestone Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking (contracts) Compile-time breaking contracts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant