numaxiom 0.0.2

Lightweight numeric marker traits for ranges/signs plus constants and ops; std by default, no_std optional.
Documentation
/// Truncate toward zero.
///
/// Contract (minimum): drop the fractional part toward zero. Implementers must
/// document behavior for NaN/∞ inputs and whether the result is exact or
/// approximate.
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);
}