From cd4ed38404384bdb13500f1d2e782d32ece2b239 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 5 Jan 2015 18:30:55 +1100 Subject: [PATCH] Deprecate the constant-returning functions in Float. These are replaced by the equivalent constants in `std::f32` and `std::f64` respectively. [breaking-change] --- src/libcore/num/f32.rs | 10 ++++++++++ src/libcore/num/f64.rs | 10 ++++++++++ src/libcore/num/mod.rs | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index aab28ae9c47..d2334943b3d 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -177,33 +177,43 @@ impl Float for f32 { } #[inline] + #[deprecated] fn mantissa_digits(_: Option) -> uint { MANTISSA_DIGITS } #[inline] + #[deprecated] fn digits(_: Option) -> uint { DIGITS } #[inline] + #[deprecated] fn epsilon() -> f32 { EPSILON } #[inline] + #[deprecated] fn min_exp(_: Option) -> int { MIN_EXP } #[inline] + #[deprecated] fn max_exp(_: Option) -> int { MAX_EXP } #[inline] + #[deprecated] fn min_10_exp(_: Option) -> int { MIN_10_EXP } #[inline] + #[deprecated] fn max_10_exp(_: Option) -> int { MAX_10_EXP } #[inline] + #[deprecated] fn min_value() -> f32 { MIN_VALUE } #[inline] + #[deprecated] fn min_pos_value(_: Option) -> f32 { MIN_POS_VALUE } #[inline] + #[deprecated] fn max_value() -> f32 { MAX_VALUE } /// Returns the mantissa, exponent and sign as integers. diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index d6d9c3446e9..95cc5f22409 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -185,33 +185,43 @@ impl Float for f64 { } #[inline] + #[deprecated] fn mantissa_digits(_: Option) -> uint { MANTISSA_DIGITS } #[inline] + #[deprecated] fn digits(_: Option) -> uint { DIGITS } #[inline] + #[deprecated] fn epsilon() -> f64 { EPSILON } #[inline] + #[deprecated] fn min_exp(_: Option) -> int { MIN_EXP } #[inline] + #[deprecated] fn max_exp(_: Option) -> int { MAX_EXP } #[inline] + #[deprecated] fn min_10_exp(_: Option) -> int { MIN_10_EXP } #[inline] + #[deprecated] fn max_10_exp(_: Option) -> int { MAX_10_EXP } #[inline] + #[deprecated] fn min_value() -> f64 { MIN_VALUE } #[inline] + #[deprecated] fn min_pos_value(_: Option) -> f64 { MIN_POS_VALUE } #[inline] + #[deprecated] fn max_value() -> f64 { MAX_VALUE } /// Returns the mantissa, exponent and sign as integers. diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 87973eacc66..1f20fae2f45 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -910,12 +910,12 @@ impl_to_primitive_uint! { u32 } impl_to_primitive_uint! { u64 } macro_rules! impl_to_primitive_float_to_float { - ($SrcT:ty, $DstT:ty, $slf:expr) => ( + ($SrcT:ident, $DstT:ident, $slf:expr) => ( if size_of::<$SrcT>() <= size_of::<$DstT>() { Some($slf as $DstT) } else { let n = $slf as f64; - let max_value: $SrcT = Float::max_value(); + let max_value: $SrcT = ::$SrcT::MAX_VALUE; if -max_value as f64 <= n && n <= max_value as f64 { Some($slf as $DstT) } else { @@ -926,7 +926,7 @@ macro_rules! impl_to_primitive_float_to_float { } macro_rules! impl_to_primitive_float { - ($T:ty) => ( + ($T:ident) => ( impl ToPrimitive for $T { #[inline] fn to_int(&self) -> Option { Some(*self as int) } @@ -1251,24 +1251,34 @@ pub trait Float // FIXME (#5527): These should be associated constants /// Returns the number of binary digits of mantissa that this type supports. + #[deprecated = "use `std::f32::MANTISSA_DIGITS` or `std::f64::MANTISSA_DIGITS` as appropriate"] fn mantissa_digits(unused_self: Option) -> uint; /// Returns the number of base-10 digits of precision that this type supports. + #[deprecated = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate"] fn digits(unused_self: Option) -> uint; /// Returns the difference between 1.0 and the smallest representable number larger than 1.0. + #[deprecated = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate"] fn epsilon() -> Self; /// Returns the minimum binary exponent that this type can represent. + #[deprecated = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate"] fn min_exp(unused_self: Option) -> int; /// Returns the maximum binary exponent that this type can represent. + #[deprecated = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate"] fn max_exp(unused_self: Option) -> int; /// Returns the minimum base-10 exponent that this type can represent. + #[deprecated = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate"] fn min_10_exp(unused_self: Option) -> int; /// Returns the maximum base-10 exponent that this type can represent. + #[deprecated = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate"] fn max_10_exp(unused_self: Option) -> int; /// Returns the smallest finite value that this type can represent. + #[deprecated = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate"] fn min_value() -> Self; /// Returns the smallest normalized positive number that this type can represent. + #[deprecated = "use `std::f32::MIN_POS_VALUE` or `std::f64::MIN_POS_VALUE` as appropriate"] fn min_pos_value(unused_self: Option) -> Self; /// Returns the largest finite value that this type can represent. + #[deprecated = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate"] fn max_value() -> Self; /// Returns true if this value is NaN and false otherwise.