From 0734122e759828cd9c69348f4cbf272f7a51bf47 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 16 Sep 2024 11:46:05 -0700 Subject: [PATCH] ratio: ord methods --- ratio_ops/src/ratio.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ratio_ops/src/ratio.rs b/ratio_ops/src/ratio.rs index a7f8928..55732be 100644 --- a/ratio_ops/src/ratio.rs +++ b/ratio_ops/src/ratio.rs @@ -68,6 +68,32 @@ impl_ratio_method!(Add,add,add_ratio); impl_ratio_method!(Sub,sub,sub_ratio); impl_ratio_method!(Rem,rem,rem_ratio); +macro_rules! impl_ratio_ord_method { + ($method:ident, $ratio_method:ident, $output:ty) => { + impl Ratio{ + #[inline] + pub fn $ratio_method(self,rhs:Ratio)->$output + where + LhsNum:core::ops::Mul, + LhsDen:core::ops::Mul, + T:Ord, + { + (self.num*rhs.den).$method(&(self.den*rhs.num)) + } + } + } +} +//PartialEq +impl_ratio_ord_method!(eq,eq_ratio,bool); +//PartialOrd +impl_ratio_ord_method!(lt,lt_ratio,bool); +impl_ratio_ord_method!(gt,gt_ratio,bool); +impl_ratio_ord_method!(le,le_ratio,bool); +impl_ratio_ord_method!(ge,ge_ratio,bool); +impl_ratio_ord_method!(partial_cmp,partial_cmp_ratio,Option); +//Ord +impl_ratio_ord_method!(cmp,cmp_ratio,core::cmp::Ordering); + /* generic rhs mul is not possible! impl core::ops::Mul> for Lhs where