Adding default implementation

This commit is contained in:
James Lucas 2016-09-22 19:56:44 +01:00
parent a64cf66f4c
commit 381942eb4f
1 changed files with 11 additions and 1 deletions

View File

@ -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
@ -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.
///