rutil 0.2.0

A library containing utilities for creating programs in rust.
Documentation
/// Logarithm operations.
pub trait LogarithmOps {
    /// Returns the natural logarithm of the number.
    fn ln(self) -> Self;

    /// Returns the logarithm of the number with respect to an arbitrary base.
    ///
    /// The result might not be correctly rounded owing to implementation details;
    /// `self.log2()` can produce more accurate results for base 2, and
    /// `self.log10()` can produce more accurate results for base 10.
    fn log(self, base: Self) -> Self;

    /// Returns the base 2 logarithm of the number.
    fn log2(self) -> Self;

    /// Returns the base 10 logarithm of the number.
    fn log10(self) -> Self;
}

/// Implements [`LogarithmOps`].
macro_rules! impl_logarithm {
    ($($t:ty),*) => {
        $(impl LogarithmOps for $t {
            #[inline] fn ln(self) -> Self { self.ln() }
            #[inline] fn log(self, base: Self) -> Self { self.log(base) }
            #[inline] fn log2(self) -> Self { self.log2() }
            #[inline] fn log10(self) -> Self { self.log10() }
        })*
    };
}

impl_logarithm!(f32, f64);