ratio: ord methods
This commit is contained in:
parent
4e284311e1
commit
0734122e75
@ -68,6 +68,32 @@ impl_ratio_method!(Add,add,add_ratio);
|
|||||||
impl_ratio_method!(Sub,sub,sub_ratio);
|
impl_ratio_method!(Sub,sub,sub_ratio);
|
||||||
impl_ratio_method!(Rem,rem,rem_ratio);
|
impl_ratio_method!(Rem,rem,rem_ratio);
|
||||||
|
|
||||||
|
macro_rules! impl_ratio_ord_method {
|
||||||
|
($method:ident, $ratio_method:ident, $output:ty) => {
|
||||||
|
impl<LhsNum,LhsDen> Ratio<LhsNum,LhsDen>{
|
||||||
|
#[inline]
|
||||||
|
pub fn $ratio_method<RhsNum,RhsDen,T>(self,rhs:Ratio<RhsNum,RhsDen>)->$output
|
||||||
|
where
|
||||||
|
LhsNum:core::ops::Mul<RhsDen,Output=T>,
|
||||||
|
LhsDen:core::ops::Mul<RhsNum,Output=T>,
|
||||||
|
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<core::cmp::Ordering>);
|
||||||
|
//Ord
|
||||||
|
impl_ratio_ord_method!(cmp,cmp_ratio,core::cmp::Ordering);
|
||||||
|
|
||||||
/* generic rhs mul is not possible!
|
/* generic rhs mul is not possible!
|
||||||
impl<Lhs,RhsNum,RhsDen> core::ops::Mul<Ratio<RhsNum,RhsDen>> for Lhs
|
impl<Lhs,RhsNum,RhsDen> core::ops::Mul<Ratio<RhsNum,RhsDen>> for Lhs
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user