Skip to content

Commit 57ad77b

Browse files
committed
Add associated constants on floats, deprecate same module level consts
1 parent 7bb3a45 commit 57ad77b

File tree

2 files changed

+163
-28
lines changed

2 files changed

+163
-28
lines changed

src/libcore/num/f32.rs

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,70 @@ use crate::num::FpCategory;
1515

1616
/// The radix or base of the internal representation of `f32`.
1717
#[stable(feature = "rust1", since = "1.0.0")]
18-
pub const RADIX: u32 = 2;
18+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
19+
pub const RADIX: u32 = f32::RADIX;
1920

2021
/// Number of significant digits in base 2.
2122
#[stable(feature = "rust1", since = "1.0.0")]
22-
pub const MANTISSA_DIGITS: u32 = 24;
23+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
24+
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
2325
/// Approximate number of significant digits in base 10.
2426
#[stable(feature = "rust1", since = "1.0.0")]
25-
pub const DIGITS: u32 = 6;
27+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
28+
pub const DIGITS: u32 = f32::DIGITS;
2629

2730
/// [Machine epsilon] value for `f32`.
2831
///
2932
/// This is the difference between `1.0` and the next larger representable number.
3033
///
3134
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3235
#[stable(feature = "rust1", since = "1.0.0")]
33-
pub const EPSILON: f32 = 1.1920929e-7_f32;
36+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
37+
pub const EPSILON: f32 = f32::EPSILON;
3438

3539
/// Smallest finite `f32` value.
3640
#[stable(feature = "rust1", since = "1.0.0")]
37-
pub const MIN: f32 = -3.40282347e+38_f32;
41+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
42+
pub const MIN: f32 = f32::MIN;
3843
/// Smallest positive normal `f32` value.
3944
#[stable(feature = "rust1", since = "1.0.0")]
40-
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
45+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
46+
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
4147
/// Largest finite `f32` value.
4248
#[stable(feature = "rust1", since = "1.0.0")]
43-
pub const MAX: f32 = 3.40282347e+38_f32;
49+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
50+
pub const MAX: f32 = f32::MAX;
4451

4552
/// One greater than the minimum possible normal power of 2 exponent.
4653
#[stable(feature = "rust1", since = "1.0.0")]
47-
pub const MIN_EXP: i32 = -125;
54+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
55+
pub const MIN_EXP: i32 = f32::MIN_EXP;
4856
/// Maximum possible power of 2 exponent.
4957
#[stable(feature = "rust1", since = "1.0.0")]
50-
pub const MAX_EXP: i32 = 128;
58+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
59+
pub const MAX_EXP: i32 = f32::MAX_EXP;
5160

5261
/// Minimum possible normal power of 10 exponent.
5362
#[stable(feature = "rust1", since = "1.0.0")]
54-
pub const MIN_10_EXP: i32 = -37;
63+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
64+
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
5565
/// Maximum possible power of 10 exponent.
5666
#[stable(feature = "rust1", since = "1.0.0")]
57-
pub const MAX_10_EXP: i32 = 38;
67+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
68+
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
5869

5970
/// Not a Number (NaN).
6071
#[stable(feature = "rust1", since = "1.0.0")]
61-
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
72+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
73+
pub const NAN: f32 = f32::NAN;
6274
/// Infinity (∞).
6375
#[stable(feature = "rust1", since = "1.0.0")]
64-
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
76+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
77+
pub const INFINITY: f32 = f32::INFINITY;
6578
/// Negative infinity (−∞).
6679
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
80+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
81+
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;
6882

6983
/// Basic mathematical constants.
7084
#[stable(feature = "rust1", since = "1.0.0")]
@@ -153,6 +167,60 @@ pub mod consts {
153167
#[lang = "f32"]
154168
#[cfg(not(test))]
155169
impl f32 {
170+
/// The radix or base of the internal representation of `f32`.
171+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
172+
pub const RADIX: u32 = 2;
173+
174+
/// Number of significant digits in base 2.
175+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
176+
pub const MANTISSA_DIGITS: u32 = 24;
177+
178+
/// Approximate number of significant digits in base 10.
179+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
180+
pub const DIGITS: u32 = 6;
181+
182+
/// [Machine epsilon] value for `f32`.
183+
///
184+
/// This is the difference between `1.0` and the next larger representable number.
185+
///
186+
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
187+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
188+
pub const EPSILON: f32 = 1.19209290e-07_f32;
189+
190+
/// Smallest finite `f32` value.
191+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
192+
pub const MIN: f32 = -3.40282347e+38_f32;
193+
/// Smallest positive normal `f32` value.
194+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
195+
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
196+
/// Largest finite `f32` value.
197+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
198+
pub const MAX: f32 = 3.40282347e+38_f32;
199+
200+
/// One greater than the minimum possible normal power of 2 exponent.
201+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
202+
pub const MIN_EXP: i32 = -125;
203+
/// Maximum possible power of 2 exponent.
204+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
205+
pub const MAX_EXP: i32 = 128;
206+
207+
/// Minimum possible normal power of 10 exponent.
208+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
209+
pub const MIN_10_EXP: i32 = -37;
210+
/// Maximum possible power of 10 exponent.
211+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
212+
pub const MAX_10_EXP: i32 = 38;
213+
214+
/// Not a Number (NaN).
215+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
216+
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
217+
/// Infinity (∞).
218+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
219+
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
220+
/// Negative infinity (-∞).
221+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
222+
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
223+
156224
/// Returns `true` if this value is `NaN`.
157225
///
158226
/// ```

src/libcore/num/f64.rs

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,70 @@ use crate::num::FpCategory;
1515

1616
/// The radix or base of the internal representation of `f64`.
1717
#[stable(feature = "rust1", since = "1.0.0")]
18-
pub const RADIX: u32 = 2;
18+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
19+
pub const RADIX: u32 = f64::RADIX;
1920

2021
/// Number of significant digits in base 2.
2122
#[stable(feature = "rust1", since = "1.0.0")]
22-
pub const MANTISSA_DIGITS: u32 = 53;
23+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
24+
pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;
2325
/// Approximate number of significant digits in base 10.
2426
#[stable(feature = "rust1", since = "1.0.0")]
25-
pub const DIGITS: u32 = 15;
27+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
28+
pub const DIGITS: u32 = f64::DIGITS;
2629

2730
/// [Machine epsilon] value for `f64`.
2831
///
2932
/// This is the difference between `1.0` and the next larger representable number.
3033
///
3134
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3235
#[stable(feature = "rust1", since = "1.0.0")]
33-
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
36+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
37+
pub const EPSILON: f64 = f64::EPSILON;
3438

3539
/// Smallest finite `f64` value.
3640
#[stable(feature = "rust1", since = "1.0.0")]
37-
pub const MIN: f64 = -1.7976931348623157e+308_f64;
41+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
42+
pub const MIN: f64 = f64::MIN;
3843
/// Smallest positive normal `f64` value.
3944
#[stable(feature = "rust1", since = "1.0.0")]
40-
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
45+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
46+
pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE;
4147
/// Largest finite `f64` value.
4248
#[stable(feature = "rust1", since = "1.0.0")]
43-
pub const MAX: f64 = 1.7976931348623157e+308_f64;
49+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
50+
pub const MAX: f64 = f64::MAX;
4451

4552
/// One greater than the minimum possible normal power of 2 exponent.
4653
#[stable(feature = "rust1", since = "1.0.0")]
47-
pub const MIN_EXP: i32 = -1021;
54+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
55+
pub const MIN_EXP: i32 = f64::MIN_EXP;
4856
/// Maximum possible power of 2 exponent.
4957
#[stable(feature = "rust1", since = "1.0.0")]
50-
pub const MAX_EXP: i32 = 1024;
58+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
59+
pub const MAX_EXP: i32 = f64::MAX_EXP;
5160

5261
/// Minimum possible normal power of 10 exponent.
5362
#[stable(feature = "rust1", since = "1.0.0")]
54-
pub const MIN_10_EXP: i32 = -307;
63+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
64+
pub const MIN_10_EXP: i32 = f64::MIN_10_EXP;
5565
/// Maximum possible power of 10 exponent.
5666
#[stable(feature = "rust1", since = "1.0.0")]
57-
pub const MAX_10_EXP: i32 = 308;
67+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
68+
pub const MAX_10_EXP: i32 = f64::MAX_10_EXP;
5869

5970
/// Not a Number (NaN).
6071
#[stable(feature = "rust1", since = "1.0.0")]
61-
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
72+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
73+
pub const NAN: f64 = f64::NAN;
6274
/// Infinity (∞).
6375
#[stable(feature = "rust1", since = "1.0.0")]
64-
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
76+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
77+
pub const INFINITY: f64 = f64::INFINITY;
6578
/// Negative infinity (−∞).
6679
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
80+
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant")]
81+
pub const NEG_INFINITY: f64 = f64::NEG_INFINITY;
6882

6983
/// Basic mathematical constants.
7084
#[stable(feature = "rust1", since = "1.0.0")]
@@ -153,6 +167,59 @@ pub mod consts {
153167
#[lang = "f64"]
154168
#[cfg(not(test))]
155169
impl f64 {
170+
/// The radix or base of the internal representation of `f64`.
171+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
172+
pub const RADIX: u32 = 2;
173+
174+
/// Number of significant digits in base 2.
175+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
176+
pub const MANTISSA_DIGITS: u32 = 53;
177+
/// Approximate number of significant digits in base 10.
178+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
179+
pub const DIGITS: u32 = 15;
180+
181+
/// [Machine epsilon] value for `f64`.
182+
///
183+
/// This is the difference between `1.0` and the next larger representable number.
184+
///
185+
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
186+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
187+
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
188+
189+
/// Smallest finite `f64` value.
190+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
191+
pub const MIN: f64 = -1.7976931348623157e+308_f64;
192+
/// Smallest positive normal `f64` value.
193+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
194+
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
195+
/// Largest finite `f64` value.
196+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
197+
pub const MAX: f64 = 1.7976931348623157e+308_f64;
198+
199+
/// One greater than the minimum possible normal power of 2 exponent.
200+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
201+
pub const MIN_EXP: i32 = -1021;
202+
/// Maximum possible power of 2 exponent.
203+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
204+
pub const MAX_EXP: i32 = 1024;
205+
206+
/// Minimum possible normal power of 10 exponent.
207+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
208+
pub const MIN_10_EXP: i32 = -307;
209+
/// Maximum possible power of 10 exponent.
210+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
211+
pub const MAX_10_EXP: i32 = 308;
212+
213+
/// Not a Number (NaN).
214+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
215+
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
216+
/// Infinity (∞).
217+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
218+
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
219+
/// Negative infinity (-∞).
220+
#[stable(feature = "assoc_int_consts", since = "1.42.0")]
221+
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
222+
156223
/// Returns `true` if this value is `NaN`.
157224
///
158225
/// ```

0 commit comments

Comments
 (0)