ratio_ops: fix Ord for Ratio
This commit is contained in:
parent
d638e633ba
commit
5cffc03ef6
@ -268,30 +268,35 @@ impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialEq<Ratio<RhsNum,RhsDen>> for Ratio<
|
|||||||
}
|
}
|
||||||
impl<Num,Den> Eq for Ratio<Num,Den> where Self:PartialEq{}
|
impl<Num,Den> Eq for Ratio<Num,Den> where Self:PartialEq{}
|
||||||
|
|
||||||
|
// Wow! These were both completely wrong!
|
||||||
|
// Idea: use a 'signed' trait instead of parity and float the sign to the numerator.
|
||||||
impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialOrd<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
|
impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialOrd<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
|
||||||
where
|
where
|
||||||
LhsNum:Copy,
|
LhsNum:Copy,
|
||||||
LhsDen:Copy,
|
LhsDen:Copy+Parity,
|
||||||
RhsNum:Copy,
|
RhsNum:Copy,
|
||||||
RhsDen:Copy,
|
RhsDen:Copy+Parity,
|
||||||
LhsNum:core::ops::Mul<RhsDen,Output=T>,
|
LhsNum:core::ops::Mul<RhsDen,Output=T>,
|
||||||
|
LhsDen:core::ops::Mul<RhsNum,Output=T>,
|
||||||
RhsNum:core::ops::Mul<LhsDen,Output=U>,
|
RhsNum:core::ops::Mul<LhsDen,Output=U>,
|
||||||
T:PartialOrd<U>,
|
RhsDen:core::ops::Mul<LhsNum,Output=U>,
|
||||||
|
T:PartialOrd<U>+Ord,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self,other:&Ratio<RhsNum,RhsDen>)->Option<core::cmp::Ordering>{
|
fn partial_cmp(&self,&other:&Ratio<RhsNum,RhsDen>)->Option<core::cmp::Ordering>{
|
||||||
(self.num*other.den).partial_cmp(&(other.num*self.den))
|
self.partial_cmp_ratio(other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<Num,Den,T> Ord for Ratio<Num,Den>
|
impl<Num,Den,T> Ord for Ratio<Num,Den>
|
||||||
where
|
where
|
||||||
Num:Copy,
|
Num:Copy,
|
||||||
Den:Copy,
|
Den:Copy+Parity,
|
||||||
Num:core::ops::Mul<Den,Output=T>,
|
Num:core::ops::Mul<Den,Output=T>,
|
||||||
|
Den:core::ops::Mul<Num,Output=T>,
|
||||||
T:Ord,
|
T:Ord,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self,other:&Self)->std::cmp::Ordering{
|
fn cmp(&self,&other:&Self)->std::cmp::Ordering{
|
||||||
(self.num*other.den).cmp(&(other.num*self.den))
|
self.cmp_ratio(other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user