Function cuprate_helper::num::cmp_float

source ·
pub fn cmp_float<F: Float>(a: F, b: F) -> Ordering
Expand description

Compare 2 non-NaN floats.

assert_eq!(cmp_float(0.0, 1.0), Ordering::Less);
assert_eq!(cmp_float(1.0, 1.0), Ordering::Equal);
assert_eq!(cmp_float(2.0, 1.0), Ordering::Greater);

assert_eq!(cmp_float(1.0,           f32::INFINITY), Ordering::Less);
assert_eq!(cmp_float(f32::INFINITY, f32::INFINITY), Ordering::Equal);
assert_eq!(cmp_float(f32::INFINITY, 1.0),           Ordering::Greater);

assert_eq!(cmp_float(f32::NEG_INFINITY, f32::INFINITY),     Ordering::Less);
assert_eq!(cmp_float(f32::NEG_INFINITY, f32::NEG_INFINITY), Ordering::Equal);
assert_eq!(cmp_float(f32::INFINITY,     f32::NEG_INFINITY), Ordering::Greater);

§Panic

This function panics if either floats are NaNs.

cmp_float(0.0, f32::NAN);