rutil 0.2.0

A library containing utilities for creating programs in rust.
Documentation
use std::num::FpCategory;

/// Classification operations.
pub trait ClassificationOps {
    /// Returns `true` if this value is `NaN`.
    fn is_nan(self) -> bool;

    /// Returns `true` if this value is positive infinity or negative infinity, and
    /// `false` otherwise.
    fn is_infinite(self) -> bool;

    /// Returns `true` if this number is neither infinite nor `NaN`.
    fn is_finite(self) -> bool;

    /// Returns `true` if the number is [subnormal].
    fn is_subnormal(self) -> bool;

    /// Returns `true` if the number is neither zero, infinite,
    /// [subnormal], or `NaN`.
    fn is_normal(self) -> bool;

    /// Returns the floating point category of the number. If only one property
    /// is going to be tested, it is generally faster to use the specific
    /// predicate instead.
    fn classify(self) -> FpCategory;
}

/// Implements [`ClassificationOps`].
macro_rules! impl_classification {
    ($($t:ty),*) => {
        $(impl ClassificationOps for $t {
            #[inline] fn is_nan(self) -> bool { self.is_nan() }
            #[inline] fn is_infinite(self) -> bool { self.is_infinite() }
            #[inline] fn is_finite(self) -> bool { self.is_finite() }
            #[inline] fn is_subnormal(self) -> bool { self.is_subnormal() }
            #[inline] fn is_normal(self) -> bool { self.is_normal() }
            #[inline] fn classify(self) -> FpCategory { self.classify() }
        })*
    };
}

impl_classification!(f32, f64);