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
Prev Previous commit
Adding default implementation
  • Loading branch information
AtheMathmo committed Sep 22, 2016
commit 381942eb4f023f11c1c2d92d54f03b92eb6312ea
12 changes: 11 additions & 1 deletion traits/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::mem;
use std::ops::Neg;
use std::num::FpCategory;

// Used for default implementation of `epsilon`
use std::f32;

use {Num, NumCast};

// FIXME: these doctests aren't actually helpful, because they're using and
Expand Down Expand Up @@ -99,7 +102,14 @@ pub trait Float
///
/// assert_eq!(x, f64::EPSILON);
/// ```
fn epsilon() -> Self;
///
/// # Panics
///
/// The default implementation will panic if `f32::EPSILON` cannot
/// be cast to `Self`.
fn epsilon() -> Self {
Self::from(f32::EPSILON).expect("Unable to cast from f32::EPSILON")
}

/// Returns the largest finite value that this type can represent.
///
Expand Down