numaxiom 0.0.2

Lightweight numeric marker traits for ranges/signs plus constants and ops; std by default, no_std optional.
Documentation
/// Square root helper.
pub trait Sqrt: Sized {
    /// Returns the square root of `self`.
    ///
    /// Implementations should document domain requirements (e.g., non-negative
    /// inputs) and how they signal invalid inputs.
    fn sqrt(self) -> Self;
}

#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
    use super::Sqrt;

    #[inline]
    fn sqrt_f32(x: f32) -> f32 {
        #[cfg(feature = "libm")]
        {
            libm::sqrtf(x)
        }
        #[cfg(not(feature = "libm"))]
        {
            f32::sqrt(x)
        }
    }

    #[inline]
    fn sqrt_f64(x: f64) -> f64 {
        #[cfg(feature = "libm")]
        {
            libm::sqrt(x)
        }
        #[cfg(not(feature = "libm"))]
        {
            f64::sqrt(x)
        }
    }

    macro_rules! impl_sqrt_for_float {
        ($ty:ty, $fn:ident) => {
            impl Sqrt for $ty {
                fn sqrt(self) -> Self {
                    $fn(self)
                }
            }
        };
    }

    impl_sqrt_for_float!(f32, sqrt_f32);
    impl_sqrt_for_float!(f64, sqrt_f64);
}