use crate::num::comparison::traits::{
OrdAbsDouble, OrdDouble, PartialOrdAbsDouble, PartialOrdDouble,
};
use core::cmp::Ordering::{self, *};
macro_rules! impl_ord_double_unsigned {
($t:ident) => {
impl OrdDouble for $t {
#[inline]
fn cmp_double(&self, other: &Self) -> Ordering {
if other.leading_zeros() == 0 {
Less
} else {
self.cmp(&(other << 1))
}
}
}
impl PartialOrdDouble for $t {
#[inline]
fn partial_cmp_double(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp_double(other))
}
}
};
}
apply_to_unsigneds!(impl_ord_double_unsigned);
macro_rules! impl_ord_abs_double_signed {
($t:ident) => {
impl OrdAbsDouble for $t {
#[inline]
fn cmp_abs_double(&self, other: &Self) -> Ordering {
self.unsigned_abs().cmp_double(&other.unsigned_abs())
}
}
impl PartialOrdAbsDouble for $t {
#[inline]
fn partial_cmp_abs_double(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp_abs_double(other))
}
}
};
}
apply_to_signeds!(impl_ord_abs_double_signed);