Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing epsilon function to retrieve EPSILON constant #231

Merged
merged 2 commits into from
Sep 22, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions traits/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ pub trait Float
/// ```
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.
///
/// ```
Expand Down Expand Up @@ -936,6 +948,11 @@ macro_rules! float_impl {
::std::$T::MIN_POSITIVE
}

#[inline]
fn epsilon() -> Self {
::std::$T::EPSILON
}

#[inline]
fn max_value() -> Self {
::std::$T::MAX
Expand Down