use std::cmp::{Ordering, PartialOrd};
macro_rules! compare_float_types {
($fn_name_: ident, $type_: ident) => {
pub fn $fn_name_(a: $type_, b: $type_) -> Ordering {
match (a, b) {
(x, y) if x.is_nan() && y.is_nan() => Ordering::Equal,
(x, _) if x.is_nan() => Ordering::Greater,
(_, y) if y.is_nan() => Ordering::Less,
(_, _) => a.partial_cmp(&b).unwrap(),
}
}
};
}
compare_float_types! { compare_floats, f64}
compare_float_types! { compare_floats_f32, f32}
pub fn unwrap_from_result<T>(result: Result<T, T>) -> T {
match result {
Ok(result) => result,
Err(result) => result,
}
}