macro up wide traits

This commit is contained in:
Quaternions 2024-08-28 15:32:33 -07:00
parent ac250e9d84
commit e604ce83e9

View File

@ -1,6 +1,6 @@
use std::ops::{Add,Mul}; use std::ops::{Add,Mul};
use crate::ratio::Ratio; use crate::ratio::Ratio;
use fixed_wide_traits::wide::{WideMul,WideDiv}; use fixed_wide_traits::wide::{WideMul,WideDiv,WideDot,WideCross};
impl<Num,Den:Copy> Ratio<Num,Den> impl<Num,Den:Copy> Ratio<Num,Den>
{ {
@ -25,18 +25,25 @@ impl<Num,Den:Copy> Ratio<Num,Den>
} }
} }
} }
impl<Num,Den,T> WideMul<T> for Ratio<Num,Den> macro_rules! impl_mul_operator {
($struct:ident,$trait:ident,$method:ident)=>{
impl<Num,Den,Rhs> $trait<Rhs> for $struct<Num,Den>
where where
Num:WideMul<T>, Num:$trait<Rhs>,
{ {
type Output=Ratio<<Num as WideMul<T>>::Output,Den>; type Output=$struct<<Num as $trait<Rhs>>::Output,Den>;
fn wide_mul(self,rhs:T)->Ratio<<Num as WideMul<T>>::Output,Den>{ fn $method(self,rhs:Rhs)->Self::Output{
Ratio{ $struct{
num:self.num.wide_mul(rhs), num:self.num.$method(rhs),
den:self.den, den:self.den,
} }
} }
} }
}
}
impl_mul_operator!(Ratio,WideMul,wide_mul);
impl_mul_operator!(Ratio,WideDot,wide_dot);
impl_mul_operator!(Ratio,WideCross,wide_cross);
impl<Num,Den,T> WideDiv<T> for Ratio<Num,Den> impl<Num,Den,T> WideDiv<T> for Ratio<Num,Den>
where where
Den:WideMul<T>, Den:WideMul<T>,