Skip to content

Commit cd4ed38

Browse files
committed
Deprecate the constant-returning functions in Float.
These are replaced by the equivalent constants in `std::f32` and `std::f64` respectively. [breaking-change]
1 parent cfb2e2a commit cd4ed38

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/libcore/num/f32.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,33 +177,43 @@ impl Float for f32 {
177177
}
178178

179179
#[inline]
180+
#[deprecated]
180181
fn mantissa_digits(_: Option<f32>) -> uint { MANTISSA_DIGITS }
181182

182183
#[inline]
184+
#[deprecated]
183185
fn digits(_: Option<f32>) -> uint { DIGITS }
184186

185187
#[inline]
188+
#[deprecated]
186189
fn epsilon() -> f32 { EPSILON }
187190

188191
#[inline]
192+
#[deprecated]
189193
fn min_exp(_: Option<f32>) -> int { MIN_EXP }
190194

191195
#[inline]
196+
#[deprecated]
192197
fn max_exp(_: Option<f32>) -> int { MAX_EXP }
193198

194199
#[inline]
200+
#[deprecated]
195201
fn min_10_exp(_: Option<f32>) -> int { MIN_10_EXP }
196202

197203
#[inline]
204+
#[deprecated]
198205
fn max_10_exp(_: Option<f32>) -> int { MAX_10_EXP }
199206

200207
#[inline]
208+
#[deprecated]
201209
fn min_value() -> f32 { MIN_VALUE }
202210

203211
#[inline]
212+
#[deprecated]
204213
fn min_pos_value(_: Option<f32>) -> f32 { MIN_POS_VALUE }
205214

206215
#[inline]
216+
#[deprecated]
207217
fn max_value() -> f32 { MAX_VALUE }
208218

209219
/// Returns the mantissa, exponent and sign as integers.

src/libcore/num/f64.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,43 @@ impl Float for f64 {
185185
}
186186

187187
#[inline]
188+
#[deprecated]
188189
fn mantissa_digits(_: Option<f64>) -> uint { MANTISSA_DIGITS }
189190

190191
#[inline]
192+
#[deprecated]
191193
fn digits(_: Option<f64>) -> uint { DIGITS }
192194

193195
#[inline]
196+
#[deprecated]
194197
fn epsilon() -> f64 { EPSILON }
195198

196199
#[inline]
200+
#[deprecated]
197201
fn min_exp(_: Option<f64>) -> int { MIN_EXP }
198202

199203
#[inline]
204+
#[deprecated]
200205
fn max_exp(_: Option<f64>) -> int { MAX_EXP }
201206

202207
#[inline]
208+
#[deprecated]
203209
fn min_10_exp(_: Option<f64>) -> int { MIN_10_EXP }
204210

205211
#[inline]
212+
#[deprecated]
206213
fn max_10_exp(_: Option<f64>) -> int { MAX_10_EXP }
207214

208215
#[inline]
216+
#[deprecated]
209217
fn min_value() -> f64 { MIN_VALUE }
210218

211219
#[inline]
220+
#[deprecated]
212221
fn min_pos_value(_: Option<f64>) -> f64 { MIN_POS_VALUE }
213222

214223
#[inline]
224+
#[deprecated]
215225
fn max_value() -> f64 { MAX_VALUE }
216226

217227
/// Returns the mantissa, exponent and sign as integers.

src/libcore/num/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,12 @@ impl_to_primitive_uint! { u32 }
910910
impl_to_primitive_uint! { u64 }
911911

912912
macro_rules! impl_to_primitive_float_to_float {
913-
($SrcT:ty, $DstT:ty, $slf:expr) => (
913+
($SrcT:ident, $DstT:ident, $slf:expr) => (
914914
if size_of::<$SrcT>() <= size_of::<$DstT>() {
915915
Some($slf as $DstT)
916916
} else {
917917
let n = $slf as f64;
918-
let max_value: $SrcT = Float::max_value();
918+
let max_value: $SrcT = ::$SrcT::MAX_VALUE;
919919
if -max_value as f64 <= n && n <= max_value as f64 {
920920
Some($slf as $DstT)
921921
} else {
@@ -926,7 +926,7 @@ macro_rules! impl_to_primitive_float_to_float {
926926
}
927927

928928
macro_rules! impl_to_primitive_float {
929-
($T:ty) => (
929+
($T:ident) => (
930930
impl ToPrimitive for $T {
931931
#[inline]
932932
fn to_int(&self) -> Option<int> { Some(*self as int) }
@@ -1251,24 +1251,34 @@ pub trait Float
12511251
// FIXME (#5527): These should be associated constants
12521252

12531253
/// Returns the number of binary digits of mantissa that this type supports.
1254+
#[deprecated = "use `std::f32::MANTISSA_DIGITS` or `std::f64::MANTISSA_DIGITS` as appropriate"]
12541255
fn mantissa_digits(unused_self: Option<Self>) -> uint;
12551256
/// Returns the number of base-10 digits of precision that this type supports.
1257+
#[deprecated = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate"]
12561258
fn digits(unused_self: Option<Self>) -> uint;
12571259
/// Returns the difference between 1.0 and the smallest representable number larger than 1.0.
1260+
#[deprecated = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate"]
12581261
fn epsilon() -> Self;
12591262
/// Returns the minimum binary exponent that this type can represent.
1263+
#[deprecated = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate"]
12601264
fn min_exp(unused_self: Option<Self>) -> int;
12611265
/// Returns the maximum binary exponent that this type can represent.
1266+
#[deprecated = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate"]
12621267
fn max_exp(unused_self: Option<Self>) -> int;
12631268
/// Returns the minimum base-10 exponent that this type can represent.
1269+
#[deprecated = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate"]
12641270
fn min_10_exp(unused_self: Option<Self>) -> int;
12651271
/// Returns the maximum base-10 exponent that this type can represent.
1272+
#[deprecated = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate"]
12661273
fn max_10_exp(unused_self: Option<Self>) -> int;
12671274
/// Returns the smallest finite value that this type can represent.
1275+
#[deprecated = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate"]
12681276
fn min_value() -> Self;
12691277
/// Returns the smallest normalized positive number that this type can represent.
1278+
#[deprecated = "use `std::f32::MIN_POS_VALUE` or `std::f64::MIN_POS_VALUE` as appropriate"]
12701279
fn min_pos_value(unused_self: Option<Self>) -> Self;
12711280
/// Returns the largest finite value that this type can represent.
1281+
#[deprecated = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate"]
12721282
fn max_value() -> Self;
12731283

12741284
/// Returns true if this value is NaN and false otherwise.

0 commit comments

Comments
 (0)