use std::ops::*;
mod number_ops;
use number_ops::*;
pub trait Number:
Sized + Copy + Clone + PartialEq + PartialOrd +
Add<Output = Self> + AddAssign +
Sub<Output = Self> + SubAssign +
Mul<Output = Self> + MulAssign +
Div<Output = Self> + DivAssign +
Rem<Output = Self> + RemAssign +
ConvertOps +
SizeOps +
SignOps +
ClampOps +
EuclidOps +
{}
macro_rules! impl_number {
($($t:ty),*) => {
$(impl Number for $t {})*
};
}
impl_number!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64);
pub trait Unsigned: Number {}
macro_rules! impl_unsigned {
($($t:ty),*) => {
$(impl Unsigned for $t {})*
};
}
impl_unsigned!(u8, u16, u32, u64, u128, usize);
pub trait Signed:
Number +
Neg<Output = Self> +
{}
macro_rules! impl_signed {
($($t:ty),*) => {
$(impl Signed for $t {})*
};
}
impl_signed!(i8, i16, i32, i64, i128, isize, f32, f64);
mod integer_ops;
use std::num::ParseIntError;
use integer_ops::*;
pub trait Integer:
Number +
BitOps +
BitCountingOps +
BitConversionOps +
IntSignOps +
CheckedOps +
SaturatingOps +
WrappingOps +
OverflowingOps +
IntEuclidOps +
PowOps +
{
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}
macro_rules! impl_integer {
($($t:ty),*) => {
$(impl Integer for $t {
#[inline]
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
Self::from_str_radix(src, radix)
}
})*
};
}
impl_integer!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
pub trait UnsignedInteger: Unsigned {
fn is_power_of_two(self) -> bool;
fn next_power_of_two(self) -> Self;
fn checked_next_power_of_two(self) -> Option<Self>;
}
macro_rules! impl_unsigned_integer {
($($t:ty),*) => {
$(impl UnsignedInteger for $t {
#[inline] fn is_power_of_two(self) -> bool { self.is_power_of_two() }
#[inline] fn next_power_of_two(self) -> Self { self.next_power_of_two() }
#[inline] fn checked_next_power_of_two(self) -> Option<Self> { self.checked_next_power_of_two() }
})*
};
}
impl_unsigned_integer!(u8, u16, u32, u64, u128, usize);
pub trait SignedInteger: Signed {}
macro_rules! impl_signed_integer {
($($t:ty),*) => {
$(impl SignedInteger for $t {})*
};
}
impl_signed_integer!(i8, i16, i32, i64, i128, isize);
mod core_float_ops;
use core_float_ops::*;
pub trait CoreFloat:
Signed +
FloatConstants +
ClassificationOps +
{
fn recip(self) -> Self;
fn to_degrees(self) -> Self;
fn to_radians(self) -> Self;
}
macro_rules! impl_core_float {
($($t:ty),*) => {
$(impl CoreFloat for $t {
#[inline] fn recip(self) -> Self { self.recip() }
#[inline] fn to_degrees(self) -> Self { self.to_degrees() }
#[inline] fn to_radians(self) -> Self { self.to_radians() }
})*
};
}
impl_core_float!(f32, f64);
mod float_ops;
use float_ops::*;
pub trait Float:
CoreFloat +
FloatRoundOps +
TrigonometricOps +
LogarithmOps +
HyperbolicOps +
{
fn copysign(self, sign: Self) -> Self;
fn mul_add(self, a: Self, b: Self) -> Self;
fn powi(self, n: i32) -> Self;
fn powf(self, n: Self) -> Self;
fn sqrt(self) -> Self;
fn exp(self) -> Self;
fn exp2(self) -> Self;
fn cbrt(self) -> Self;
fn exp_m1(self) -> Self;
fn ln_1p(self) -> Self;
}
macro_rules! impl_float {
($($t:ty),*) => {
$(impl Float for $t {
#[inline] fn copysign(self, sign: Self) -> Self { self.copysign(sign) }
#[inline] fn mul_add(self, a: Self, b: Self) -> Self { self.mul_add(a, b) }
#[inline] fn powi(self, n: i32) -> Self { self.powi(n) }
#[inline] fn powf(self, n: Self) -> Self { self.powf(n) }
#[inline] fn sqrt(self) -> Self { self.sqrt() }
#[inline] fn exp(self) -> Self { self.exp() }
#[inline] fn exp2(self) -> Self { self.exp2() }
#[inline] fn cbrt(self) -> Self { self.cbrt() }
#[inline] fn exp_m1(self) -> Self { self.exp_m1() }
#[inline] fn ln_1p(self) -> Self { self.ln_1p() }
})*
};
}
impl_float!(f32, f64);