use std::ops::{Add,Mul}; use crate::ratio::Ratio; use fixed_wide_traits::wide::{WideMul,WideDiv,WideDot,WideCross}; impl Ratio { pub fn rational_add(self,rhs:T)->Ratio<>::Output>>::Output,Den> where Den:Mul, Num:Add<>::Output>, { Ratio{ num:self.num+self.den.mul(rhs), den:self.den, } } pub fn wide_rational_add(self,rhs:T)->Ratio<>::Output>>::Output,Den> where Den:WideMul, Num:Add<>::Output>, { Ratio{ num:self.num+self.den.wide_mul(rhs), den:self.den, } } } macro_rules! impl_mul_operator { ($struct:ident,$trait:ident,$method:ident)=>{ impl $trait for $struct where Num:$trait, { type Output=$struct<>::Output,Den>; fn $method(self,rhs:Rhs)->Self::Output{ $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 WideDiv for Ratio where Den:WideMul, { type Output=Ratio>::Output>; fn wide_div(self,rhs:T)->Ratio>::Output>{ Ratio{ num:self.num, den:self.den.wide_mul(rhs), } } }