add min_pos_value constant for floats
Follow-up on issue #13297 and PR #13710. Instead of following the (confusing) C/C++ approach of using `MIN_VALUE` for the smallest *positive* number, we introduce `MIN_POS_VALUE` (and in the Float trait, `min_pos_value`) to represent this number. This patch also removes a few remaining redundantly-defined constants that were missed last time around.
This commit is contained in:
@@ -190,7 +190,9 @@ pub fn pow<T: One + Mul<T, T>>(mut base: T, mut exp: uint) -> T {
|
||||
/// Numbers which have upper and lower bounds
|
||||
pub trait Bounded {
|
||||
// FIXME (#5527): These should be associated constants
|
||||
/// returns the smallest finite number this type can represent
|
||||
fn min_value() -> Self;
|
||||
/// returns the largest finite number this type can represent
|
||||
fn max_value() -> Self;
|
||||
}
|
||||
|
||||
@@ -356,6 +358,8 @@ pub trait Float: Signed + Primitive {
|
||||
/// Returns the category that this number falls into.
|
||||
fn classify(self) -> FPCategory;
|
||||
|
||||
// FIXME (#5527): These should be associated constants
|
||||
|
||||
/// Returns the number of binary digits of mantissa that this type supports.
|
||||
fn mantissa_digits(unused_self: Option<Self>) -> uint;
|
||||
/// Returns the number of base-10 digits of precision that this type supports.
|
||||
@@ -370,6 +374,8 @@ pub trait Float: Signed + Primitive {
|
||||
fn min_10_exp(unused_self: Option<Self>) -> int;
|
||||
/// Returns the maximum base-10 exponent that this type can represent.
|
||||
fn max_10_exp(unused_self: Option<Self>) -> int;
|
||||
/// Returns the smallest normalized positive number that this type can represent.
|
||||
fn min_pos_value(unused_self: Option<Self>) -> Self;
|
||||
|
||||
/// Constructs a floating point number created by multiplying `x` by 2
|
||||
/// raised to the power of `exp`.
|
||||
@@ -434,6 +440,8 @@ pub trait Float: Signed + Primitive {
|
||||
/// legs of length `x` and `y`.
|
||||
fn hypot(self, other: Self) -> Self;
|
||||
|
||||
// FIXME (#5527): These should be associated constants
|
||||
|
||||
/// Archimedes' constant.
|
||||
fn pi() -> Self;
|
||||
/// 2.0 * pi.
|
||||
|
||||
Reference in New Issue
Block a user