diff --git a/ratio_ops/src/ratio.rs b/ratio_ops/src/ratio.rs index fdb5f39eb..a7f8928d6 100644 --- a/ratio_ops/src/ratio.rs +++ b/ratio_ops/src/ratio.rs @@ -175,3 +175,48 @@ macro_rules! impl_ratio_assign_operator { impl_ratio_assign_operator!(AddAssign,add_assign); impl_ratio_assign_operator!(SubAssign,sub_assign); impl_ratio_assign_operator!(RemAssign,rem_assign); + +// Only implement PartialEq<Self> +// Rust's operators aren't actually that good + +impl<Num,Den,T> PartialEq for Ratio<Num,Den> + where + Num:Copy, + Den:Copy, + Num:core::ops::Mul<Den,Output=T>, + T:PartialEq, +{ + #[inline] + fn eq(&self,&other:&Self)->bool{ + (self.num*other.den).eq(&(other.num*self.den)) + } +} +impl<Num,Den> Eq for Ratio<Num,Den> + where + Ratio<Num,Den>:PartialEq, +{} + +impl<Num,Den,T> PartialOrd for Ratio<Num,Den> + where + Num:Copy, + Den:Copy, + Num:core::ops::Mul<Den,Output=T>, + T:PartialOrd, +{ + #[inline] + fn partial_cmp(&self,&other:&Self)->Option<core::cmp::Ordering>{ + (self.num*other.den).partial_cmp(&(other.num*self.den)) + } +} +impl<Num,Den,T> Ord for Ratio<Num,Den> + where + Num:Copy, + Den:Copy, + Num:core::ops::Mul<Den,Output=T>, + T:Ord, +{ + #[inline] + fn cmp(&self,other:&Self)->std::cmp::Ordering{ + (self.num*other.den).cmp(&(other.num*self.den)) + } +}