mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
factor::numeric::OverflowingAdd: Generate impls with a macro
This commit is contained in:
parent
b25c77c5f9
commit
d2b43f49f9
1 changed files with 11 additions and 14 deletions
|
@ -198,21 +198,18 @@ impl<T: DoubleInt> Arithmetic for Montgomery<T> {
|
|||
pub(crate) trait OverflowingAdd: Sized {
|
||||
fn overflowing_add_(self, n: Self) -> (Self, bool);
|
||||
}
|
||||
impl OverflowingAdd for u32 {
|
||||
fn overflowing_add_(self, n: Self) -> (Self, bool) {
|
||||
self.overflowing_add(n)
|
||||
}
|
||||
}
|
||||
impl OverflowingAdd for u64 {
|
||||
fn overflowing_add_(self, n: Self) -> (Self, bool) {
|
||||
self.overflowing_add(n)
|
||||
}
|
||||
}
|
||||
impl OverflowingAdd for u128 {
|
||||
fn overflowing_add_(self, n: Self) -> (Self, bool) {
|
||||
self.overflowing_add(n)
|
||||
}
|
||||
macro_rules! overflowing {
|
||||
($x:ty) => {
|
||||
impl OverflowingAdd for $x {
|
||||
fn overflowing_add_(self, n: Self) -> (Self, bool) {
|
||||
self.overflowing_add(n)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
overflowing!(u32);
|
||||
overflowing!(u64);
|
||||
overflowing!(u128);
|
||||
|
||||
pub(crate) trait Int:
|
||||
Display + Debug + PrimInt + OverflowingAdd + WrappingNeg + WrappingSub + WrappingMul
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue