-
Notifications
You must be signed in to change notification settings - Fork 346
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
Uint256 implementation #1059
Uint256 implementation #1059
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.
Nice!
Now with this we can make Uint128::full_mul
public and return an Uint256
.
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.
lgtm.
All the commends have been addressed! |
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.
💪
} | ||
|
||
/// Multiplies two u128 values without overflow. | ||
fn full_mul(self, rhs: impl Into<u128>) -> U256 { | ||
U256::from(self.u128()) * U256::from(rhs.into()) | ||
pub fn full_mul(self, rhs: impl Into<u128>) -> Uint256 { |
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.
This new API is nice. Could you add a CHANGELOG entry and an example doc for it?
@@ -4,6 +4,9 @@ mod system_error; | |||
mod verification_error; | |||
|
|||
pub use recover_pubkey_error::RecoverPubkeyError; | |||
pub use std_error::{DivideByZeroError, OverflowError, OverflowOperation, StdError, StdResult}; | |||
pub use std_error::{ | |||
ConversionOverflowError, DivideByZeroError, OverflowError, OverflowOperation, StdError, |
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.
ConversionOverflowError
also need to be exported in lib.rs because it is used in StdError now.
panic!( | ||
"right shift error: {} is larger than the number of bits in Uint256", | ||
"right shift error: {} is larger or equal than the number of bits in Uint256", |
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.
👍🏼 This is being handled in the other impls by delegating to the checked variant and unwrapping. Nice to have consistent behaviour here.
What about a checked_shr
, by the way? I guess it's not currently needed / used. But wouldn't be bad to have; particularly because it doesn't panic.
Also includes
Isqrt
implementation forUint64
,Uint128
andUint256
.Closes #1053
Closes #1054