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 {
where ($struct:ident,$trait:ident,$method:ident)=>{
Num:WideMul<T>, impl<Num,Den,Rhs> $trait<Rhs> for $struct<Num,Den>
{ where
type Output=Ratio<<Num as WideMul<T>>::Output,Den>; Num:$trait<Rhs>,
fn wide_mul(self,rhs:T)->Ratio<<Num as WideMul<T>>::Output,Den>{ {
Ratio{ type Output=$struct<<Num as $trait<Rhs>>::Output,Den>;
num:self.num.wide_mul(rhs), fn $method(self,rhs:Rhs)->Self::Output{
den:self.den, $struct{
num:self.num.$method(rhs),
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>,