From e604ce83e92807e4c8c928ce108a67ee72f5dcc1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 28 Aug 2024 15:32:33 -0700 Subject: [PATCH] macro up wide traits --- deferred_division/src/wide.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/deferred_division/src/wide.rs b/deferred_division/src/wide.rs index df7dcae..c2e1205 100644 --- a/deferred_division/src/wide.rs +++ b/deferred_division/src/wide.rs @@ -1,6 +1,6 @@ use std::ops::{Add,Mul}; use crate::ratio::Ratio; -use fixed_wide_traits::wide::{WideMul,WideDiv}; +use fixed_wide_traits::wide::{WideMul,WideDiv,WideDot,WideCross}; impl Ratio { @@ -25,18 +25,25 @@ impl Ratio } } } -impl WideMul for Ratio - where - Num:WideMul, -{ - type Output=Ratio<>::Output,Den>; - fn wide_mul(self,rhs:T)->Ratio<>::Output,Den>{ - Ratio{ - num:self.num.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,