Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ totaleq_impl!(uint)

totaleq_impl!(char)

totaleq_impl!(f32)
totaleq_impl!(f64)

#[deriving(Clone, Eq)]
pub enum Ordering { Less = -1, Equal = 0, Greater = 1 }

Expand Down Expand Up @@ -126,6 +129,9 @@ totalord_impl!(uint)

totalord_impl!(char)

totalord_impl!(f32)
totalord_impl!(f64)

/// Compares (a1, b1) against (a2, b2), where the a values are more significant.
pub fn cmp2<A:TotalOrd,B:TotalOrd>(
a1: &A, b1: &B,
Expand Down Expand Up @@ -216,6 +222,18 @@ mod test {
assert!(!2.equals(&17));
}

#[test]
fn test_f32_totaleq() {
assert!(3.14f32.cmp(3.0f32), Less);
assert!(4.12f32.cmp(4.11f32), Greater);
}

#[test]
fn test_f64_totaleq() {
assert!(3.14f64.cmp(3.0f64), Less);
assert!(4.12f64.cmp(4.11f64), Greater);
}

#[test]
fn test_ordering_order() {
assert!(Less < Equal);
Expand Down