pub trait Log: Sized {
fn ln(self) -> Self;
}
#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
use super::Log;
fn ln_f32(x: f32) -> f32 {
#[cfg(feature = "libm")]
{
libm::logf(x)
}
#[cfg(not(feature = "libm"))]
{
f32::ln(x)
}
}
fn ln_f64(x: f64) -> f64 {
#[cfg(feature = "libm")]
{
libm::log(x)
}
#[cfg(not(feature = "libm"))]
{
f64::ln(x)
}
}
macro_rules! impl_log_for_float {
($ty:ty, $fn:ident) => {
impl Log for $ty {
fn ln(self) -> Self {
$fn(self)
}
}
};
}
impl_log_for_float!(f32, ln_f32);
impl_log_for_float!(f64, ln_f64);
}