aboutsummaryrefslogtreecommitdiff
path: root/src/lisp/number.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp/number.rs')
-rw-r--r--src/lisp/number.rs21
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 @@
1use std::{ 1use 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
82impl Eq for LispNumber {}
83
84impl 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
96impl PartialOrd for LispNumber {
97 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
98 Some(self.cmp(other))
99 }
100}
101
81impl fmt::Display for LispNumber { 102impl 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 {