Skip to content

Commit c4071d0

Browse files
committed
Auto merge of #68325 - faern:move-numeric-consts-to-associated-consts-step1, r=LukasKalbertodt
Move numeric consts to associated consts step1 A subset of #67913. Implements the first step of RFC rust-lang/rfcs#2700 This PR adds the new constants as unstable constants and defines the old ones in terms of the new ones. Then fix a tiny bit of code that started having naming collisions because of the new assoc consts. Removed a test that did not seem relevant any longer. Since doing just `u8::MIN` should now indeed be valid.
2 parents 3024c4e + 61fecfb commit c4071d0

File tree

10 files changed

+207
-77
lines changed

10 files changed

+207
-77
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#![feature(const_type_id)]
135135
#![feature(const_caller_location)]
136136
#![cfg_attr(bootstrap, feature(slice_patterns))]
137+
#![feature(assoc_int_consts)]
137138

138139
#[prelude_import]
139140
#[allow(unused)]

src/libcore/num/dec2flt/rawfp.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ macro_rules! other_constants {
129129
($type: ident) => {
130130
const EXPLICIT_SIG_BITS: u8 = Self::SIG_BITS - 1;
131131
const MAX_EXP: i16 = (1 << (Self::EXP_BITS - 1)) - 1;
132-
const MIN_EXP: i16 = -Self::MAX_EXP + 1;
133-
const MAX_EXP_INT: i16 = Self::MAX_EXP - (Self::SIG_BITS as i16 - 1);
132+
const MIN_EXP: i16 = -<Self as RawFloat>::MAX_EXP + 1;
133+
const MAX_EXP_INT: i16 = <Self as RawFloat>::MAX_EXP - (Self::SIG_BITS as i16 - 1);
134134
const MAX_ENCODED_EXP: i16 = (1 << Self::EXP_BITS) - 1;
135-
const MIN_EXP_INT: i16 = Self::MIN_EXP - (Self::SIG_BITS as i16 - 1);
135+
const MIN_EXP_INT: i16 = <Self as RawFloat>::MIN_EXP - (Self::SIG_BITS as i16 - 1);
136136
const MAX_SIG: u64 = (1 << Self::SIG_BITS) - 1;
137137
const MIN_SIG: u64 = 1 << (Self::SIG_BITS - 1);
138138

139-
const INFINITY: Self = $crate::$type::INFINITY;
140-
const NAN: Self = $crate::$type::NAN;
139+
const INFINITY: Self = $type::INFINITY;
140+
const NAN: Self = $type::NAN;
141141
const ZERO: Self = 0.0;
142142
};
143143
}

src/libcore/num/f32.rs

+68-14
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,56 @@ 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+
pub const RADIX: u32 = f32::RADIX;
1919

2020
/// Number of significant digits in base 2.
2121
#[stable(feature = "rust1", since = "1.0.0")]
22-
pub const MANTISSA_DIGITS: u32 = 24;
22+
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
2323
/// Approximate number of significant digits in base 10.
2424
#[stable(feature = "rust1", since = "1.0.0")]
25-
pub const DIGITS: u32 = 6;
25+
pub const DIGITS: u32 = f32::DIGITS;
2626

2727
/// [Machine epsilon] value for `f32`.
2828
///
2929
/// This is the difference between `1.0` and the next larger representable number.
3030
///
3131
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3232
#[stable(feature = "rust1", since = "1.0.0")]
33-
pub const EPSILON: f32 = 1.1920929e-7_f32;
33+
pub const EPSILON: f32 = f32::EPSILON;
3434

3535
/// Smallest finite `f32` value.
3636
#[stable(feature = "rust1", since = "1.0.0")]
37-
pub const MIN: f32 = -3.40282347e+38_f32;
37+
pub const MIN: f32 = f32::MIN;
3838
/// Smallest positive normal `f32` value.
3939
#[stable(feature = "rust1", since = "1.0.0")]
40-
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
40+
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
4141
/// Largest finite `f32` value.
4242
#[stable(feature = "rust1", since = "1.0.0")]
43-
pub const MAX: f32 = 3.40282347e+38_f32;
43+
pub const MAX: f32 = f32::MAX;
4444

4545
/// One greater than the minimum possible normal power of 2 exponent.
4646
#[stable(feature = "rust1", since = "1.0.0")]
47-
pub const MIN_EXP: i32 = -125;
47+
pub const MIN_EXP: i32 = f32::MIN_EXP;
4848
/// Maximum possible power of 2 exponent.
4949
#[stable(feature = "rust1", since = "1.0.0")]
50-
pub const MAX_EXP: i32 = 128;
50+
pub const MAX_EXP: i32 = f32::MAX_EXP;
5151

5252
/// Minimum possible normal power of 10 exponent.
5353
#[stable(feature = "rust1", since = "1.0.0")]
54-
pub const MIN_10_EXP: i32 = -37;
54+
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
5555
/// Maximum possible power of 10 exponent.
5656
#[stable(feature = "rust1", since = "1.0.0")]
57-
pub const MAX_10_EXP: i32 = 38;
57+
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
5858

5959
/// Not a Number (NaN).
6060
#[stable(feature = "rust1", since = "1.0.0")]
61-
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
61+
pub const NAN: f32 = f32::NAN;
6262
/// Infinity (∞).
6363
#[stable(feature = "rust1", since = "1.0.0")]
64-
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
64+
pub const INFINITY: f32 = f32::INFINITY;
6565
/// Negative infinity (−∞).
6666
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
67+
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;
6868

6969
/// Basic mathematical constants.
7070
#[stable(feature = "rust1", since = "1.0.0")]
@@ -153,6 +153,60 @@ pub mod consts {
153153
#[lang = "f32"]
154154
#[cfg(not(test))]
155155
impl f32 {
156+
/// The radix or base of the internal representation of `f32`.
157+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
158+
pub const RADIX: u32 = 2;
159+
160+
/// Number of significant digits in base 2.
161+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
162+
pub const MANTISSA_DIGITS: u32 = 24;
163+
164+
/// Approximate number of significant digits in base 10.
165+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
166+
pub const DIGITS: u32 = 6;
167+
168+
/// [Machine epsilon] value for `f32`.
169+
///
170+
/// This is the difference between `1.0` and the next larger representable number.
171+
///
172+
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
173+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
174+
pub const EPSILON: f32 = 1.19209290e-07_f32;
175+
176+
/// Smallest finite `f32` value.
177+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
178+
pub const MIN: f32 = -3.40282347e+38_f32;
179+
/// Smallest positive normal `f32` value.
180+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
181+
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
182+
/// Largest finite `f32` value.
183+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
184+
pub const MAX: f32 = 3.40282347e+38_f32;
185+
186+
/// One greater than the minimum possible normal power of 2 exponent.
187+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
188+
pub const MIN_EXP: i32 = -125;
189+
/// Maximum possible power of 2 exponent.
190+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
191+
pub const MAX_EXP: i32 = 128;
192+
193+
/// Minimum possible normal power of 10 exponent.
194+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
195+
pub const MIN_10_EXP: i32 = -37;
196+
/// Maximum possible power of 10 exponent.
197+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
198+
pub const MAX_10_EXP: i32 = 38;
199+
200+
/// Not a Number (NaN).
201+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
202+
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
203+
/// Infinity (∞).
204+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
205+
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
206+
/// Negative infinity (-∞).
207+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
208+
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
209+
156210
/// Returns `true` if this value is `NaN`.
157211
///
158212
/// ```

src/libcore/num/f64.rs

+67-14
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,56 @@ 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+
pub const RADIX: u32 = f64::RADIX;
1919

2020
/// Number of significant digits in base 2.
2121
#[stable(feature = "rust1", since = "1.0.0")]
22-
pub const MANTISSA_DIGITS: u32 = 53;
22+
pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;
2323
/// Approximate number of significant digits in base 10.
2424
#[stable(feature = "rust1", since = "1.0.0")]
25-
pub const DIGITS: u32 = 15;
25+
pub const DIGITS: u32 = f64::DIGITS;
2626

2727
/// [Machine epsilon] value for `f64`.
2828
///
2929
/// This is the difference between `1.0` and the next larger representable number.
3030
///
3131
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3232
#[stable(feature = "rust1", since = "1.0.0")]
33-
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
33+
pub const EPSILON: f64 = f64::EPSILON;
3434

3535
/// Smallest finite `f64` value.
3636
#[stable(feature = "rust1", since = "1.0.0")]
37-
pub const MIN: f64 = -1.7976931348623157e+308_f64;
37+
pub const MIN: f64 = f64::MIN;
3838
/// Smallest positive normal `f64` value.
3939
#[stable(feature = "rust1", since = "1.0.0")]
40-
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
40+
pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE;
4141
/// Largest finite `f64` value.
4242
#[stable(feature = "rust1", since = "1.0.0")]
43-
pub const MAX: f64 = 1.7976931348623157e+308_f64;
43+
pub const MAX: f64 = f64::MAX;
4444

4545
/// One greater than the minimum possible normal power of 2 exponent.
4646
#[stable(feature = "rust1", since = "1.0.0")]
47-
pub const MIN_EXP: i32 = -1021;
47+
pub const MIN_EXP: i32 = f64::MIN_EXP;
4848
/// Maximum possible power of 2 exponent.
4949
#[stable(feature = "rust1", since = "1.0.0")]
50-
pub const MAX_EXP: i32 = 1024;
50+
pub const MAX_EXP: i32 = f64::MAX_EXP;
5151

5252
/// Minimum possible normal power of 10 exponent.
5353
#[stable(feature = "rust1", since = "1.0.0")]
54-
pub const MIN_10_EXP: i32 = -307;
54+
pub const MIN_10_EXP: i32 = f64::MIN_10_EXP;
5555
/// Maximum possible power of 10 exponent.
5656
#[stable(feature = "rust1", since = "1.0.0")]
57-
pub const MAX_10_EXP: i32 = 308;
57+
pub const MAX_10_EXP: i32 = f64::MAX_10_EXP;
5858

5959
/// Not a Number (NaN).
6060
#[stable(feature = "rust1", since = "1.0.0")]
61-
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
61+
pub const NAN: f64 = f64::NAN;
6262
/// Infinity (∞).
6363
#[stable(feature = "rust1", since = "1.0.0")]
64-
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
64+
pub const INFINITY: f64 = f64::INFINITY;
6565
/// Negative infinity (−∞).
6666
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
67+
pub const NEG_INFINITY: f64 = f64::NEG_INFINITY;
6868

6969
/// Basic mathematical constants.
7070
#[stable(feature = "rust1", since = "1.0.0")]
@@ -153,6 +153,59 @@ pub mod consts {
153153
#[lang = "f64"]
154154
#[cfg(not(test))]
155155
impl f64 {
156+
/// The radix or base of the internal representation of `f64`.
157+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
158+
pub const RADIX: u32 = 2;
159+
160+
/// Number of significant digits in base 2.
161+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
162+
pub const MANTISSA_DIGITS: u32 = 53;
163+
/// Approximate number of significant digits in base 10.
164+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
165+
pub const DIGITS: u32 = 15;
166+
167+
/// [Machine epsilon] value for `f64`.
168+
///
169+
/// This is the difference between `1.0` and the next larger representable number.
170+
///
171+
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
172+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
173+
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
174+
175+
/// Smallest finite `f64` value.
176+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
177+
pub const MIN: f64 = -1.7976931348623157e+308_f64;
178+
/// Smallest positive normal `f64` value.
179+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
180+
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
181+
/// Largest finite `f64` value.
182+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
183+
pub const MAX: f64 = 1.7976931348623157e+308_f64;
184+
185+
/// One greater than the minimum possible normal power of 2 exponent.
186+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
187+
pub const MIN_EXP: i32 = -1021;
188+
/// Maximum possible power of 2 exponent.
189+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
190+
pub const MAX_EXP: i32 = 1024;
191+
192+
/// Minimum possible normal power of 10 exponent.
193+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
194+
pub const MIN_10_EXP: i32 = -307;
195+
/// Maximum possible power of 10 exponent.
196+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
197+
pub const MAX_10_EXP: i32 = 308;
198+
199+
/// Not a Number (NaN).
200+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
201+
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
202+
/// Infinity (∞).
203+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
204+
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
205+
/// Negative infinity (-∞).
206+
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
207+
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
208+
156209
/// Returns `true` if this value is `NaN`.
157210
///
158211
/// ```

0 commit comments

Comments
 (0)