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