Add more constants to FloatCore

This commit is contained in:
Josh Stone 2018-02-27 16:31:36 -08:00
parent 7d6575da0f
commit 99c6cc11ba
1 changed files with 65 additions and 0 deletions

View File

@ -21,6 +21,21 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
/// Returns NaN.
fn nan() -> Self;
/// Returns `-0.0`.
fn neg_zero() -> Self;
/// Returns the smallest finite value that this type can represent.
fn min_value() -> Self;
/// Returns the smallest positive, normalized value that this type can represent.
fn min_positive_value() -> Self;
/// Returns epsilon, a small positive value.
fn epsilon() -> Self;
/// Returns the largest finite value that this type can represent.
fn max_value() -> Self;
/// Returns `true` if the number is NaN.
#[inline]
fn is_nan(self) -> bool {
@ -163,6 +178,31 @@ impl FloatCore for f32 {
::core::f32::NAN
}
#[inline]
fn neg_zero() -> Self {
-0.0
}
#[inline]
fn min_value() -> Self {
::core::f32::MIN
}
#[inline]
fn min_positive_value() -> Self {
::core::f32::MIN_POSITIVE
}
#[inline]
fn epsilon() -> Self {
::core::f32::EPSILON
}
#[inline]
fn max_value() -> Self {
::core::f32::MAX
}
#[inline]
#[cfg(not(feature = "std"))]
fn classify(self) -> FpCategory {
@ -227,6 +267,31 @@ impl FloatCore for f64 {
::core::f64::NAN
}
#[inline]
fn neg_zero() -> Self {
-0.0
}
#[inline]
fn min_value() -> Self {
::core::f64::MIN
}
#[inline]
fn min_positive_value() -> Self {
::core::f64::MIN_POSITIVE
}
#[inline]
fn epsilon() -> Self {
::core::f64::EPSILON
}
#[inline]
fn max_value() -> Self {
::core::f64::MAX
}
#[inline]
#[cfg(not(feature = "std"))]
fn classify(self) -> FpCategory {