pub trait LogBase: Sized {
fn log_base(self, base: Self) -> Self;
}
#[cfg(any(feature = "std", feature = "libm"))]
mod float_impls {
use super::LogBase;
#[inline]
fn log_base_f32(x: f32, base: f32) -> f32 {
#[cfg(feature = "libm")]
{
libm::logf(x) / libm::logf(base)
}
#[cfg(not(feature = "libm"))]
{
f32::ln(x) / f32::ln(base)
}
}
#[inline]
fn log_base_f64(x: f64, base: f64) -> f64 {
#[cfg(feature = "libm")]
{
libm::log(x) / libm::log(base)
}
#[cfg(not(feature = "libm"))]
{
f64::ln(x) / f64::ln(base)
}
}
macro_rules! impl_log_base_for_float {
($ty:ty, $fn:ident) => {
impl LogBase for $ty {
fn log_base(self, base: Self) -> Self {
$fn(self, base)
}
}
};
}
impl_log_base_for_float!(f32, log_base_f32);
impl_log_base_for_float!(f64, log_base_f64);
}