From b25c77c5f971c442ab2ca5fc4aec271270fc707f Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 1 Jul 2020 15:46:35 +0200 Subject: [PATCH] factor::numeric: Generate implementations of DoubleInt with a macro --- src/uu/factor/src/numeric.rs | 40 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/uu/factor/src/numeric.rs b/src/uu/factor/src/numeric.rs index d2fc7604b..bbfce9f26 100644 --- a/src/uu/factor/src/numeric.rs +++ b/src/uu/factor/src/numeric.rs @@ -252,32 +252,26 @@ macro_rules! int { } }; } +macro_rules! double_int { + ( $x:ty, $y:ty ) => { + int!($x); + impl DoubleInt for $x { + type Double = $y; -int!(u32); -int!(u64); + fn as_double(self) -> $y { + self as _ + } + fn from_double(n: $y) -> $x { + n as _ + } + } + }; +} + +double_int!(u32, u64); +double_int!(u64, u128); int!(u128); -impl DoubleInt for u64 { - type Double = u128; - - fn as_double(self) -> u128 { - self as _ - } - fn from_double(n: u128) -> u64 { - n as _ - } -} -impl DoubleInt for u32 { - type Double = u64; - - fn as_double(self) -> u64 { - self as _ - } - fn from_double(n: u64) -> u32 { - n as _ - } -} - // extended Euclid algorithm // precondition: a is odd pub(crate) fn modular_inverse(a: T) -> T {