utils/
epsilon.rs

1//!
2//!  epsilon.rs
3//!
4//!  Created by Mitchell Nordine at 03:46PM on February 02, 2015.
5//!
6//!
7
8
9/// A trait for finding the smallest fraction possible with a given Float type.
10pub trait Epsilon {
11    /// Return the difference between 1 and the next lowest value that follows 1.
12    fn epsilon() -> Self;
13}
14
15impl Epsilon for f32 {
16    #[inline]
17    fn epsilon() -> f32 { ::std::f32::EPSILON }
18}
19
20impl Epsilon for f64 {
21    #[inline]
22    fn epsilon() -> f64 { ::std::f64::EPSILON }
23}
24
25/// A helper function for bypassing the Epsilon trait's namespace where
26/// the Epsilon type can be inferred.
27#[inline]
28pub fn epsilon<F>() -> F where F: Epsilon { Epsilon::epsilon() }