wip: partial cmp
This commit is contained in:
parent
12b825bb15
commit
17d43852d3
@ -1,7 +1,19 @@
|
||||
use std::ops::{Add,Mul};
|
||||
use std::cmp::Ordering;
|
||||
use crate::ratio::Ratio;
|
||||
use fixed_wide_traits::wide::{WideMul,WideDiv};
|
||||
|
||||
impl<Num,Den,T> PartialOrd<T> for Ratio<Num,Den>
|
||||
{
|
||||
fn partial_cmp(&self,other:&T)->Option<Ordering>{
|
||||
//a < c*b
|
||||
match self.den.cmp(0){
|
||||
Ordering::Less=>Some(self.num.partial_cmp(self.den.mul(other))),
|
||||
Ordering::Equal=>None,//divide by zero
|
||||
Ordering::Greater=>Some(self.num.partial_cmp(self.den.mul(other)).reverse()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<Num,Den:Copy> Ratio<Num,Den>
|
||||
{
|
||||
pub fn rational_add<T>(self,rhs:T)->Ratio<<Num as Add<<Den as Mul<T>>::Output>>::Output,Den>
|
||||
|
Loading…
Reference in New Issue
Block a user