use std::cmp::Ordering;
use crate::float::IsFloat;
#[inline]
pub fn compare_fn_nan_min<T>(a: &T, b: &T) -> Ordering
where
T: PartialOrd + IsFloat,
{
if T::is_float() {
match (a.is_nan(), b.is_nan()) {
(false, false) => unsafe { a.partial_cmp(b).unwrap_unchecked() },
(true, true) => Ordering::Equal,
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
}
} else {
unsafe { a.partial_cmp(b).unwrap_unchecked() }
}
}
#[inline]
pub fn compare_fn_nan_max<T>(a: &T, b: &T) -> Ordering
where
T: PartialOrd + IsFloat,
{
if T::is_float() {
match (a.is_nan(), b.is_nan()) {
(false, false) => unsafe { a.partial_cmp(b).unwrap_unchecked() },
(true, true) => Ordering::Equal,
(true, false) => Ordering::Greater,
(false, true) => Ordering::Less,
}
} else {
unsafe { a.partial_cmp(b).unwrap_unchecked() }
}
}