pub trait Trunc: Sized {
fn trunc(self) -> Self;
}
#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
use super::Trunc;
#[inline]
fn trunc_f32(x: f32) -> f32 {
#[cfg(feature = "libm")]
{
libm::truncf(x)
}
#[cfg(not(feature = "libm"))]
{
f32::trunc(x)
}
}
#[inline]
fn trunc_f64(x: f64) -> f64 {
#[cfg(feature = "libm")]
{
libm::trunc(x)
}
#[cfg(not(feature = "libm"))]
{
f64::trunc(x)
}
}
macro_rules! impl_trunc_for_float {
($ty:ty, $fn:ident) => {
impl Trunc for $ty {
fn trunc(self) -> Self {
$fn(self)
}
}
};
}
impl_trunc_for_float!(f32, trunc_f32);
impl_trunc_for_float!(f64, trunc_f64);
}