Implementing epsilon function to retrieve EPSILON constant

This commit is contained in:
James Lucas 2016-09-18 14:36:44 -07:00
parent a11be641ed
commit a64cf66f4c
1 changed files with 17 additions and 0 deletions

View File

@ -89,6 +89,18 @@ pub trait Float
/// ``` /// ```
fn min_positive_value() -> Self; fn min_positive_value() -> Self;
/// Returns epsilon, a small positive value.
///
/// ```
/// use num_traits::Float;
/// use std::f64;
///
/// let x: f64 = Float::epsilon();
///
/// assert_eq!(x, f64::EPSILON);
/// ```
fn epsilon() -> Self;
/// Returns the largest finite value that this type can represent. /// Returns the largest finite value that this type can represent.
/// ///
/// ``` /// ```
@ -936,6 +948,11 @@ macro_rules! float_impl {
::std::$T::MIN_POSITIVE ::std::$T::MIN_POSITIVE
} }
#[inline]
fn epsilon() -> Self {
::std::$T::EPSILON
}
#[inline] #[inline]
fn max_value() -> Self { fn max_value() -> Self {
::std::$T::MAX ::std::$T::MAX