use std::cmp::Ordering;
pub trait NumericalValue: Copy + Default + Send + Sync + 'static {
fn total_cmp(&self, other: &Self) -> Ordering;
fn to_f64(self) -> f64;
}
macro_rules! impl_numerical_int {
($($t:ty),*) => {$(
impl NumericalValue for $t {
#[inline(always)]
fn total_cmp(&self, other: &Self) -> Ordering { Ord::cmp(self, other) }
#[inline(always)]
fn to_f64(self) -> f64 { self as f64 }
}
)*};
}
macro_rules! impl_numerical_float {
($($t:ty),*) => {$(
impl NumericalValue for $t {
#[inline(always)]
fn total_cmp(&self, other: &Self) -> Ordering { <$t>::total_cmp(self, other) }
#[inline(always)]
fn to_f64(self) -> f64 { self as f64 }
}
)*};
}
impl_numerical_int!(
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize
);
impl_numerical_float!(f32, f64);