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

fix(int): avoid infinite recursion on left shift #707

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/int/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ impl HInt for u128 {
fn widen_mul(self, rhs: Self) -> Self::D {
self.zero_widen_mul(rhs)
}

fn widen_hi(self) -> Self::D {
self.widen() << <Self as MinInt>::BITS
}
}

impl HInt for i128 {
Expand All @@ -247,6 +251,10 @@ impl HInt for i128 {
fn widen_mul(self, rhs: Self) -> Self::D {
unimplemented!("signed i128 widening multiply is not used")
}

fn widen_hi(self) -> Self::D {
self.widen() << <Self as MinInt>::BITS
}
}

impl DInt for u256 {
Expand Down
7 changes: 4 additions & 3 deletions src/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ pub(crate) trait HInt: Int {
/// around problems with associated type bounds (such as `Int<Othersign: DInt>`) being unstable
fn zero_widen(self) -> Self::D;
/// Widens the integer to have double bit width and shifts the integer into the higher bits
fn widen_hi(self) -> Self::D {
self.widen() << <Self as MinInt>::BITS
}
fn widen_hi(self) -> Self::D;
/// Widening multiplication with zero widening. This cannot overflow.
fn zero_widen_mul(self, rhs: Self) -> Self::D;
/// Widening multiplication. This cannot overflow.
Expand Down Expand Up @@ -364,6 +362,9 @@ macro_rules! impl_h_int {
fn widen_mul(self, rhs: Self) -> Self::D {
self.widen().wrapping_mul(rhs.widen())
}
fn widen_hi(self) -> Self::D {
(self as $X) << <Self as MinInt>::BITS
}
}
)*
};
Expand Down
Loading