Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmp() to f32 and f64, with tests #12193

Closed
wants to merge 1 commit into from
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