pub trait Cos: Sized {
fn cos(self) -> Self;
}
#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
use super::Cos;
#[inline]
fn cos_f32(x: f32) -> f32 {
#[cfg(feature = "libm")]
{
libm::cosf(x)
}
#[cfg(not(feature = "libm"))]
{
f32::cos(x)
}
}
#[inline]
fn cos_f64(x: f64) -> f64 {
#[cfg(feature = "libm")]
{
libm::cos(x)
}
#[cfg(not(feature = "libm"))]
{
f64::cos(x)
}
}
macro_rules! impl_cos_for_float {
($ty:ty, $fn:ident) => {
impl Cos for $ty {
fn cos(self) -> Self {
$fn(self)
}
}
};
}
impl_cos_for_float!(f32, cos_f32);
impl_cos_for_float!(f64, cos_f64);
}