From b98eba27e544ddbb52b54a6b7fa4517bd3540a49 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 9 Sep 2024 13:58:47 -0700 Subject: [PATCH] wide operators --- fixed_wide/src/fixed.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 0833068..e1cf4a8 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -178,6 +178,7 @@ macro_rules! impl_multiply_operator_not_const_generic { } } } + #[cfg(not(feature="wide-mul"))] impl_multiplicative_operator_not_const_generic!(($struct, $trait, $method, $output ), $width); } } @@ -194,6 +195,7 @@ macro_rules! impl_divide_operator_not_const_generic { } } } + #[cfg(not(feature="wide-mul"))] impl_multiplicative_operator_not_const_generic!(($struct, $trait, $method, $output ), $width); }; } @@ -279,6 +281,19 @@ impl_shift_operator!( Fixed, Shl, shl, Self ); impl_shift_assign_operator!( Fixed, ShrAssign, shr_assign ); impl_shift_operator!( Fixed, Shr, shr, Self ); +macro_rules! impl_wide_operators{ + ($lhs:expr,$rhs:expr)=>{ + impl core::ops::Mul> for Fixed<$lhs,{$lhs*32}>{ + type Output=Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>; + fn mul(self, other: Fixed<$rhs,{$rhs*32}>)->Self::Output{ + paste::item!{ + self.[](other) + } + } + } + } +} + // WIDE MUL: multiply into a wider type // let a = I32F32::ONE; // let b:I64F64 = a.wide_mul(a); @@ -306,6 +321,8 @@ macro_rules! impl_wide_not_const_generic{ } } } + #[cfg(feature="wide-mul")] + impl_wide_operators!($lhs,$rhs); }; }