opis/fraction/
comparison.rs

1use crate::Fraction;
2use std::cmp::Ordering;
3
4impl Ord for Fraction {
5
6    fn cmp(&self, b: &Self) -> Ordering {
7
8        if self.sign() == false && b.sign() == true {
9
10            Ordering::Less
11
12        } else if self.sign() == true && b.sign() == false {  
13
14            Ordering::Greater
15
16        } else {
17
18            let ad = &self.0 * &b.1;
19
20            let bc = &self.1 * &b.0;
21
22            ad.cmp(&bc)
23
24        }
25
26    }
27    
28}
29
30impl PartialOrd for Fraction {
31
32    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
33        
34        Some(self.cmp(other))
35    
36    }
37
38}