more general PartialEq + PartialOrd

This commit is contained in:
Quaternions 2024-10-03 12:25:39 -07:00
parent 64e44846aa
commit 218a7fbf0f

View File

@ -251,15 +251,18 @@ impl_ratio_assign_operator!(RemAssign,rem_assign);
// Only implement PartialEq<Self> // Only implement PartialEq<Self>
// Rust's operators aren't actually that good // Rust's operators aren't actually that good
impl<Num,Den,T> PartialEq for Ratio<Num,Den> impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialEq<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
where where
Num:Copy, LhsNum:Copy,
Den:Copy, LhsDen:Copy,
Num:core::ops::Mul<Den,Output=T>, RhsNum:Copy,
T:PartialEq, RhsDen:Copy,
LhsNum:core::ops::Mul<RhsDen,Output=T>,
RhsNum:core::ops::Mul<LhsDen,Output=U>,
T:PartialEq<U>,
{ {
#[inline] #[inline]
fn eq(&self,&other:&Self)->bool{ fn eq(&self,other:&Ratio<RhsNum,RhsDen>)->bool{
(self.num*other.den).eq(&(other.num*self.den)) (self.num*other.den).eq(&(other.num*self.den))
} }
} }
@ -268,15 +271,18 @@ impl<Num,Den> Eq for Ratio<Num,Den>
Ratio<Num,Den>:PartialEq, Ratio<Num,Den>:PartialEq,
{} {}
impl<Num,Den,T> PartialOrd for Ratio<Num,Den> impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialOrd<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
where where
Num:Copy, LhsNum:Copy,
Den:Copy, LhsDen:Copy,
Num:core::ops::Mul<Den,Output=T>, RhsNum:Copy,
T:PartialOrd, RhsDen:Copy,
LhsNum:core::ops::Mul<RhsDen,Output=T>,
RhsNum:core::ops::Mul<LhsDen,Output=U>,
T:PartialOrd<U>,
{ {
#[inline] #[inline]
fn partial_cmp(&self,&other:&Self)->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.num*other.den).partial_cmp(&(other.num*self.den))
} }
} }