use super::equal::*;
use crate::helpers::*;
pub trait NumOrd: PartialOrd + NumEq {
fn num_lt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.num_ne(other, eps) && self < other
}
fn num_le(&self, other: &Self, eps: &Self::Eps) -> bool {
self.num_eq(other, eps) || self < other
}
fn num_gt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.num_ne(other, eps) && self > other
}
fn num_ge(&self, other: &Self, eps: &Self::Eps) -> bool {
self.num_eq(other, eps) || self > other
}
}
macro_rules! float_num_order {
($type:ty) => {
impl NumOrd for $type {}
};
}
float_num_order! {f32}
float_num_order! {f64}
macro_rules! tuple_num_order {
($tuple:ty) => {
impl<T: NumOrd> NumOrd for $tuple {
fn num_gt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_gt(y, eps))
}
fn num_ge(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_ge(y, eps))
}
fn num_lt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_lt(y, eps))
}
fn num_le(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_le(y, eps))
}
}
};
($tuple:ty, $($others:ty),+) => {
tuple_num_order! {$tuple}
tuple_num_order! {$($others),+}
};
}
tuple_num_order! {(T, ), (T, T), (T, T, T), (T, T, T, T)}
macro_rules! array_num_order {
($size:expr) => {
impl<T: NumOrd + Copy> NumOrd for [T; $size] {
fn num_gt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_gt(y, eps))
}
fn num_ge(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_ge(y, eps))
}
fn num_lt(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_lt(y, eps))
}
fn num_le(&self, other: &Self, eps: &Self::Eps) -> bool {
self.all_with(other, &|x, y| x.num_le(y, eps))
}
}
};
($size:expr, $($others:expr),+) => {
array_num_order! {$size}
array_num_order! {$($others),+}
};
}
array_num_order! {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
}