Skip to content

Commit 28ecef7

Browse files
committed
core: Add impls of Eq and Ord for f32, f64
1 parent 05e7ba8 commit 28ecef7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/libcore/f32.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ pub pure fn logarithm(n: f32, b: f32) -> f32 {
138138
return log2(n) / log2(b);
139139
}
140140

141+
impl f32 : cmp::Eq {
142+
pure fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
143+
pure fn ne(&self, other: &f32) -> bool { (*self) != (*other) }
144+
}
145+
146+
impl f32 : cmp::Ord {
147+
pure fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
148+
pure fn le(&self, other: &f32) -> bool { (*self) <= (*other) }
149+
pure fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
150+
pure fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
151+
}
152+
141153
impl f32: num::Num {
142154
pure fn add(other: &f32) -> f32 { return self + *other; }
143155
pure fn sub(other: &f32) -> f32 { return self - *other; }

src/libcore/f64.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ pub pure fn logarithm(n: f64, b: f64) -> f64 {
157157
return log2(n) / log2(b);
158158
}
159159

160+
impl f64 : cmp::Eq {
161+
pure fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
162+
pure fn ne(&self, other: &f64) -> bool { (*self) != (*other) }
163+
}
164+
165+
impl f64 : cmp::Ord {
166+
pure fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
167+
pure fn le(&self, other: &f64) -> bool { (*self) <= (*other) }
168+
pure fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
169+
pure fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
170+
}
171+
160172
impl f64: num::Num {
161173
pure fn add(other: &f64) -> f64 { return self + *other; }
162174
pure fn sub(other: &f64) -> f64 { return self - *other; }

0 commit comments

Comments
 (0)