use approx::ApproxEq;
use std::cmp;
use std::fmt;
use std::ops::*;
use rust_num::{Float, Num, NumCast};
pub trait PartialOrd {
fn partial_min(self, other: Self) -> Self;
fn partial_max(self, other: Self) -> Self;
}
macro_rules! partial_ord_int (
($T:ident) => (
impl PartialOrd for $T {
fn partial_min(self, other: $T) -> $T { cmp::min(self, other) }
fn partial_max(self, other: $T) -> $T { cmp::max(self, other) }
}
)
);
partial_ord_int!(isize);
partial_ord_int!(i8);
partial_ord_int!(i16);
partial_ord_int!(i32);
partial_ord_int!(i64);
partial_ord_int!(usize);
partial_ord_int!(u8);
partial_ord_int!(u16);
partial_ord_int!(u32);
partial_ord_int!(u64);
macro_rules! partial_ord_float (
($T:ident) => (
impl PartialOrd for $T {
fn partial_min(self, other: $T) -> $T { self.min(other) }
fn partial_max(self, other: $T) -> $T { self.max(other) }
}
)
);
partial_ord_float!(f32);
partial_ord_float!(f64);
pub trait BaseNum where
Self: Copy + Clone + fmt::Debug,
Self: Num + NumCast,
Self: PartialOrd + cmp::PartialOrd,
Self: AddAssign + SubAssign,
Self: MulAssign + DivAssign + RemAssign,
{}
macro_rules! impl_basenum_int (
($T: ident) => (
impl BaseNum for $T {}
)
);
impl_basenum_int!(i8);
impl_basenum_int!(i16);
impl_basenum_int!(i32);
impl_basenum_int!(i64);
impl_basenum_int!(u8);
impl_basenum_int!(u16);
impl_basenum_int!(u32);
impl_basenum_int!(u64);
impl_basenum_int!(isize);
impl_basenum_int!(usize);
macro_rules! impl_basenum_float (
($T: ident) => (
impl BaseNum for $T {}
)
);
impl_basenum_float!(f32);
impl_basenum_float!(f64);
pub trait BaseInt : BaseNum {}
impl BaseInt for i8 {}
impl BaseInt for i16 {}
impl BaseInt for i32 {}
impl BaseInt for i64 {}
impl BaseInt for isize {}
impl BaseInt for u8 {}
impl BaseInt for u16 {}
impl BaseInt for u32 {}
impl BaseInt for u64 {}
impl BaseInt for usize {}
pub trait BaseFloat : BaseNum + Float + ApproxEq<Epsilon = Self> {}
impl BaseFloat for f32 {}
impl BaseFloat for f64 {}