use core::hash::Hash;
use crate::Number;
pub trait Int: Number + Hash + Eq + Ord {}
macro_rules! impl_int {
($($ty:ty),*) => {
$(
impl Int for $ty {}
)*
}
}
impl_int!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize);
pub trait IInt: Number + Hash + Eq + Ord {}
macro_rules! impl_iint {
($($ty:ty),*) => {
$(
impl IInt for $ty {}
)*
}
}
impl_iint!(i8, i16, i32, i64, i128, isize);
pub trait UInt: Number + Hash + Eq + Ord {
fn as_i64(self) -> i64;
}
macro_rules! impl_uint {
($($ty:ty),*) => {
$(
#[allow(clippy::cast_lossless, clippy::cast_possible_truncation)]
impl UInt for $ty {
#[allow(clippy::cast_possible_wrap)]
fn as_i64(self) -> i64 {
self as i64
}
}
)*
}
}
impl_uint!(u8, u16, u32, u64, u128, usize);
pub trait Float: Number + core::ops::Neg<Output = Self> {
const SQRT_2: Self;
#[must_use]
fn sqrt(self) -> Self;
#[must_use]
fn cbrt(self) -> Self;
#[must_use]
fn inv_sqrt(self) -> Self {
Self::ONE / self.sqrt()
}
#[must_use]
fn powf(self, exp: Self) -> Self;
#[must_use]
fn erf(self) -> Self;
#[must_use]
fn log2(self) -> Self;
}
impl Float for f32 {
const SQRT_2: Self = core::f32::consts::SQRT_2;
fn sqrt(self) -> Self {
Self::sqrt(self)
}
fn cbrt(self) -> Self {
Self::cbrt(self)
}
fn powf(self, exp: Self) -> Self {
Self::powf(self, exp)
}
fn erf(self) -> Self {
libm::erff(self)
}
fn log2(self) -> Self {
Self::log2(self)
}
}
impl Float for f64 {
const SQRT_2: Self = core::f64::consts::SQRT_2;
fn sqrt(self) -> Self {
Self::sqrt(self)
}
fn cbrt(self) -> Self {
Self::cbrt(self)
}
fn powf(self, exp: Self) -> Self {
Self::powf(self, exp)
}
fn erf(self) -> Self {
libm::erf(self)
}
fn log2(self) -> Self {
Self::log2(self)
}
}