pub trait Hypot: Sized {
fn hypot(self, other: Self) -> Self;
}
#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
use super::Hypot;
#[inline]
fn hypot_f32(x: f32, y: f32) -> f32 {
#[cfg(feature = "libm")]
{
libm::hypotf(x, y)
}
#[cfg(not(feature = "libm"))]
{
f32::hypot(x, y)
}
}
#[inline]
fn hypot_f64(x: f64, y: f64) -> f64 {
#[cfg(feature = "libm")]
{
libm::hypot(x, y)
}
#[cfg(not(feature = "libm"))]
{
f64::hypot(x, y)
}
}
macro_rules! impl_hypot_for_float {
($ty:ty, $fn:ident) => {
impl Hypot for $ty {
fn hypot(self, other: Self) -> Self {
$fn(self, other)
}
}
};
}
impl_hypot_for_float!(f32, hypot_f32);
impl_hypot_for_float!(f64, hypot_f64);
}