Skip to content

Commit

Permalink
Adding default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AtheMathmo committed Sep 22, 2016
1 parent a64cf66 commit 381942e
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 381942e

Please sign in to comment.