Rollup merge of #77009 - est31:dogfood_total_cmp, r=lcnr

Dogfood total_cmp in the test crate
This commit is contained in:
Ralf Jung 2020-09-21 15:30:49 +02:00 committed by GitHub
commit fb3cb14af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 17 deletions

View File

@ -29,6 +29,7 @@
#![feature(staged_api)]
#![feature(termination_trait_lib)]
#![feature(test)]
#![feature(total_cmp)]
// Public reexports
pub use self::bench::{black_box, Bencher};

View File

@ -1,29 +1,13 @@
#![allow(missing_docs)]
#![allow(deprecated)] // Float
use std::cmp::Ordering::{self, Equal, Greater, Less};
use std::mem;
#[cfg(test)]
mod tests;
fn local_cmp(x: f64, y: f64) -> Ordering {
// arbitrarily decide that NaNs are larger than everything.
if y.is_nan() {
Less
} else if x.is_nan() {
Greater
} else if x < y {
Less
} else if x == y {
Equal
} else {
Greater
}
}
fn local_sort(v: &mut [f64]) {
v.sort_by(|x: &f64, y: &f64| local_cmp(*x, *y));
v.sort_by(|x: &f64, y: &f64| x.total_cmp(y));
}
/// Trait that provides simple descriptive statistics on a univariate set of numeric samples.