From 99c6cc11ba1ba6b7dfc49c7f0866f8b482dc34be Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 27 Feb 2018 16:31:36 -0800 Subject: [PATCH] Add more constants to FloatCore --- src/float.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/float.rs b/src/float.rs index 7952357..7522d58 100644 --- a/src/float.rs +++ b/src/float.rs @@ -21,6 +21,21 @@ pub trait FloatCore: Num + NumCast + Neg + 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 {