diff options
Diffstat (limited to 'src/lisp/number.rs')
-rw-r--r-- | src/lisp/number.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lisp/number.rs b/src/lisp/number.rs index 23d7997..0ce5ac0 100644 --- a/src/lisp/number.rs +++ b/src/lisp/number.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}, | ||
2 | fmt, | 3 | fmt, |
3 | ops::{Add, Mul, Sub}, | 4 | ops::{Add, Mul, Sub}, |
4 | }; | 5 | }; |
@@ -78,6 +79,26 @@ impl PartialEq for LispNumber { | |||
78 | } | 79 | } |
79 | } | 80 | } |
80 | 81 | ||
82 | impl Eq for LispNumber {} | ||
83 | |||
84 | impl Ord for LispNumber { | ||
85 | fn cmp(&self, other: &Self) -> Ordering { | ||
86 | use LispNumber::*; | ||
87 | match (*self, *other) { | ||
88 | (Integer(a), Integer(b)) => a.cmp(&b), | ||
89 | (Float(a), Integer(b)) => (a as i64).cmp(&b), | ||
90 | (Integer(a), Float(b)) => a.cmp(&(b as i64)), | ||
91 | (Float(a), Float(b)) => (a as i64).cmp(&(b as i64)), | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | impl PartialOrd for LispNumber { | ||
97 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
98 | Some(self.cmp(other)) | ||
99 | } | ||
100 | } | ||
101 | |||
81 | impl fmt::Display for LispNumber { | 102 | impl fmt::Display for LispNumber { |
82 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 103 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
83 | match self { | 104 | match self { |