rutil 0.2.0

A library containing utilities for creating programs in rust.
Documentation
/// Float constants.
pub trait FloatConstants {
    /// The radix or base of the internal representation of `f32`.
    fn radix() -> u32;

    /// Number of significant digits in base 2.
    fn mantissa_digits() -> u32;

    /// Approximate number of significant digits in base 10.
    fn digits() -> u32;

    /// [Machine epsilon] value for `f32`.
    ///
    /// This is the difference between `1.0` and the next larger representable number.
    ///
    /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
    fn epsilon() -> Self;

    /// Smallest positive normal `f32` value.
    fn min_positive() -> Self;

    /// One greater than the minimum possible normal power of 2 exponent.
    fn min_exp() -> i32;

    /// Maximum possible power of 2 exponent.
    fn max_exp() -> i32;

    /// Minimum possible normal power of 10 exponent.
    fn min_10_exp() -> i32;

    /// Maximum possible power of 10 exponent.
    fn max_10_exp() -> i32;

    /// Not a Number (NaN).
    fn nan() -> Self;

    /// Infinity (∞).
    fn infinity() -> Self;

    /// Negative infinity (−∞).
    fn neg_infinity() -> Self;
}

/// Implements [`FloatConstants`].
macro_rules! impl_float_constants {
    ($($t:ty),*) => {
        $(impl FloatConstants for $t {
            #[inline] fn radix() -> u32 { Self::RADIX }
            #[inline] fn mantissa_digits() -> u32 { Self::MANTISSA_DIGITS }
            #[inline] fn digits() -> u32 { Self::DIGITS }
            #[inline] fn epsilon() -> Self { Self::EPSILON }
            #[inline] fn min_positive() -> Self { Self::MIN_POSITIVE }
            #[inline] fn min_exp() -> i32 { Self::MIN_EXP }
            #[inline] fn max_exp() -> i32 { Self::MAX_EXP }
            #[inline] fn min_10_exp() -> i32 { Self::MIN_10_EXP }
            #[inline] fn max_10_exp() -> i32 { Self::MAX_10_EXP }
            #[inline] fn nan() -> Self { Self::NAN }
            #[inline] fn infinity() -> Self { Self::INFINITY }
            #[inline] fn neg_infinity() -> Self { Self::NEG_INFINITY }
        })*
    };
}

impl_float_constants!(f32, f64);