4
4
//! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
5
5
//!
6
6
//! Mathematically significant numbers are provided in the `consts` sub-module.
7
+ //!
8
+ //! Although using these constants won’t cause compilation warnings,
9
+ //! new code should use the associated constants directly on the primitive type.
7
10
8
11
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
9
12
@@ -14,17 +17,21 @@ use crate::mem;
14
17
use crate :: num:: FpCategory ;
15
18
16
19
/// The radix or base of the internal representation of `f32`.
20
+ /// Use [`f32::RADIX`](../../std/primitive.f32.html#associatedconstant.RADIX) instead.
17
21
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
18
22
pub const RADIX : u32 = f32:: RADIX ;
19
23
20
24
/// Number of significant digits in base 2.
25
+ /// Use [`f32::MANTISSA_DIGITS`](../../std/primitive.f32.html#associatedconstant.MANTISSA_DIGITS) instead.
21
26
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
22
27
pub const MANTISSA_DIGITS : u32 = f32:: MANTISSA_DIGITS ;
23
28
/// Approximate number of significant digits in base 10.
29
+ /// Use [`f32::DIGITS`](../../std/primitive.f32.html#associatedconstant.DIGITS) instead.
24
30
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
25
31
pub const DIGITS : u32 = f32:: DIGITS ;
26
32
27
33
/// [Machine epsilon] value for `f32`.
34
+ /// Use [`f32::EPSILON`](../../std/primitive.f32.html#associatedconstant.EPSILON) instead.
28
35
///
29
36
/// This is the difference between `1.0` and the next larger representable number.
30
37
///
@@ -33,36 +40,46 @@ pub const DIGITS: u32 = f32::DIGITS;
33
40
pub const EPSILON : f32 = f32:: EPSILON ;
34
41
35
42
/// Smallest finite `f32` value.
43
+ /// Use [`f32::MIN`](../../std/primitive.f32.html#associatedconstant.MIN) instead.
36
44
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
37
45
pub const MIN : f32 = f32:: MIN ;
38
46
/// Smallest positive normal `f32` value.
47
+ /// Use [`f32::MIN_POSITIVE`](../../std/primitive.f32.html#associatedconstant.MIN_POSITIVE) instead.
39
48
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
40
49
pub const MIN_POSITIVE : f32 = f32:: MIN_POSITIVE ;
41
50
/// Largest finite `f32` value.
51
+ /// Use [`f32::MAX`](../../std/primitive.f32.html#associatedconstant.MAX) instead.
42
52
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
43
53
pub const MAX : f32 = f32:: MAX ;
44
54
45
55
/// One greater than the minimum possible normal power of 2 exponent.
56
+ /// Use [`f32::MIN_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_EXP) instead.
46
57
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
47
58
pub const MIN_EXP : i32 = f32:: MIN_EXP ;
48
59
/// Maximum possible power of 2 exponent.
60
+ /// Use [`f32::MAX_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_EXP) instead.
49
61
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
50
62
pub const MAX_EXP : i32 = f32:: MAX_EXP ;
51
63
52
64
/// Minimum possible normal power of 10 exponent.
65
+ /// Use [`f32::MIN_10_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_10_EXP) instead.
53
66
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
54
67
pub const MIN_10_EXP : i32 = f32:: MIN_10_EXP ;
55
68
/// Maximum possible power of 10 exponent.
69
+ /// Use [`f32::MAX_10_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_10_EXP) instead.
56
70
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
57
71
pub const MAX_10_EXP : i32 = f32:: MAX_10_EXP ;
58
72
59
73
/// Not a Number (NaN).
74
+ /// Use [`f32::NAN`](../../std/primitive.f32.html#associatedconstant.NAN) instead.
60
75
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
61
76
pub const NAN : f32 = f32:: NAN ;
62
77
/// Infinity (∞).
78
+ /// Use [`f32::INFINITY`](../../std/primitive.f32.html#associatedconstant.INFINITY) instead.
63
79
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
64
80
pub const INFINITY : f32 = f32:: INFINITY ;
65
81
/// Negative infinity (−∞).
82
+ /// Use [`f32::NEG_INFINITY`](../../std/primitive.f32.html#associatedconstant.NEG_INFINITY) instead.
66
83
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
67
84
pub const NEG_INFINITY : f32 = f32:: NEG_INFINITY ;
68
85
@@ -154,64 +171,62 @@ pub mod consts {
154
171
#[ cfg( not( test) ) ]
155
172
impl f32 {
156
173
/// The radix or base of the internal representation of `f32`.
157
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
174
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
158
175
pub const RADIX : u32 = 2 ;
159
176
160
177
/// Number of significant digits in base 2.
161
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
178
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
162
179
pub const MANTISSA_DIGITS : u32 = 24 ;
163
180
164
181
/// Approximate number of significant digits in base 10.
165
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
182
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
166
183
pub const DIGITS : u32 = 6 ;
167
184
168
185
/// [Machine epsilon] value for `f32`.
169
186
///
170
187
/// This is the difference between `1.0` and the next larger representable number.
171
188
///
172
189
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
173
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
190
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
174
191
pub const EPSILON : f32 = 1.19209290e-07_f32 ;
175
192
176
193
/// Smallest finite `f32` value.
177
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
194
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
178
195
pub const MIN : f32 = -3.40282347e+38_f32 ;
179
196
/// Smallest positive normal `f32` value.
180
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
197
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
181
198
pub const MIN_POSITIVE : f32 = 1.17549435e-38_f32 ;
182
199
/// Largest finite `f32` value.
183
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
200
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
184
201
pub const MAX : f32 = 3.40282347e+38_f32 ;
185
202
186
203
/// One greater than the minimum possible normal power of 2 exponent.
187
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
204
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
188
205
pub const MIN_EXP : i32 = -125 ;
189
206
/// Maximum possible power of 2 exponent.
190
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
207
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
191
208
pub const MAX_EXP : i32 = 128 ;
192
209
193
210
/// Minimum possible normal power of 10 exponent.
194
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
211
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
195
212
pub const MIN_10_EXP : i32 = -37 ;
196
213
/// Maximum possible power of 10 exponent.
197
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
214
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
198
215
pub const MAX_10_EXP : i32 = 38 ;
199
216
200
217
/// Not a Number (NaN).
201
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
218
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
202
219
pub const NAN : f32 = 0.0_f32 / 0.0_f32 ;
203
220
/// Infinity (∞).
204
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
221
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
205
222
pub const INFINITY : f32 = 1.0_f32 / 0.0_f32 ;
206
223
/// Negative infinity (-∞).
207
- #[ unstable ( feature = "assoc_int_consts" , reason = "recently added" , issue = "68490 ") ]
224
+ #[ stable ( feature = "assoc_int_consts" , since = "1.43.0 " ) ]
208
225
pub const NEG_INFINITY : f32 = -1.0_f32 / 0.0_f32 ;
209
226
210
227
/// Returns `true` if this value is `NaN`.
211
228
///
212
229
/// ```
213
- /// use std::f32;
214
- ///
215
230
/// let nan = f32::NAN;
216
231
/// let f = 7.0_f32;
217
232
///
@@ -236,8 +251,6 @@ impl f32 {
236
251
/// `false` otherwise.
237
252
///
238
253
/// ```
239
- /// use std::f32;
240
- ///
241
254
/// let f = 7.0f32;
242
255
/// let inf = f32::INFINITY;
243
256
/// let neg_inf = f32::NEG_INFINITY;
@@ -258,8 +271,6 @@ impl f32 {
258
271
/// Returns `true` if this number is neither infinite nor `NaN`.
259
272
///
260
273
/// ```
261
- /// use std::f32;
262
- ///
263
274
/// let f = 7.0f32;
264
275
/// let inf = f32::INFINITY;
265
276
/// let neg_inf = f32::NEG_INFINITY;
@@ -283,8 +294,6 @@ impl f32 {
283
294
/// [subnormal], or `NaN`.
284
295
///
285
296
/// ```
286
- /// use std::f32;
287
- ///
288
297
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
289
298
/// let max = f32::MAX;
290
299
/// let lower_than_min = 1.0e-40_f32;
@@ -312,7 +321,6 @@ impl f32 {
312
321
///
313
322
/// ```
314
323
/// use std::num::FpCategory;
315
- /// use std::f32;
316
324
///
317
325
/// let num = 12.4_f32;
318
326
/// let inf = f32::INFINITY;
@@ -372,8 +380,6 @@ impl f32 {
372
380
/// Takes the reciprocal (inverse) of a number, `1/x`.
373
381
///
374
382
/// ```
375
- /// use std::f32;
376
- ///
377
383
/// let x = 2.0_f32;
378
384
/// let abs_difference = (x.recip() - (1.0 / x)).abs();
379
385
///
@@ -388,7 +394,7 @@ impl f32 {
388
394
/// Converts radians to degrees.
389
395
///
390
396
/// ```
391
- /// use std::f32::{self, consts} ;
397
+ /// use std::f32::consts;
392
398
///
393
399
/// let angle = consts::PI;
394
400
///
@@ -407,7 +413,7 @@ impl f32 {
407
413
/// Converts degrees to radians.
408
414
///
409
415
/// ```
410
- /// use std::f32::{self, consts} ;
416
+ /// use std::f32::consts;
411
417
///
412
418
/// let angle = 180.0f32;
413
419
///
0 commit comments