Skip to content

Commit 22dcfa1

Browse files
committed
Add relevant associated constants to the float types
1 parent b5ff806 commit 22dcfa1

File tree

2 files changed

+135
-28
lines changed

2 files changed

+135
-28
lines changed

src/libcore/num/f32.rs

Lines changed: 68 additions & 14 deletions
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

Lines changed: 67 additions & 14 deletions
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)