use crate::*;
pub trait Round: Sized + Zero {
fn round(self) -> Self;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn trunc(self) -> Self;
fn atrunc(self) -> Self;
fn fract(self) -> Self;
}
macro_rules! int_impl {
($type:ident) => {
impl Round for $type {
#[inline(always)]
fn round(self) -> Self {
self
}
fn floor(self) -> Self {
self
}
fn ceil(self) -> Self {
self
}
fn trunc(self) -> Self {
self
}
fn atrunc(self) -> Self {
self
}
fn fract(self) -> Self {
self
}
}
};
}
int_impl!(u8);
int_impl!(u16);
int_impl!(u32);
int_impl!(u64);
int_impl!(u128);
int_impl!(usize);
int_impl!(i8);
int_impl!(i16);
int_impl!(i32);
int_impl!(i64);
int_impl!(i128);
int_impl!(isize);
macro_rules! float_impl {
($type:ident) => {
impl Round for $type {
fn round(self) -> Self {
self.round()
}
fn floor(self) -> Self {
self.floor()
}
fn ceil(self) -> Self {
self.ceil()
}
fn trunc(self) -> Self {
self.trunc()
}
fn atrunc(self) -> Self {
if self.is_sign_positive() {
self.ceil()
} else {
self.floor()
}
}
fn fract(self) -> Self {
self.fract()
}
}
};
}
float_impl!(f32);
float_impl!(f64);