Skip to content

Commit a992f95

Browse files
committed
Add examples for std::f32 constants.
And also point people to use the associated constants of f32 instead.
1 parent d626e4d commit a992f95

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

src/libcore/num/f32.rs

+140
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,45 @@ use crate::num::FpCategory;
1818

1919
/// The radix or base of the internal representation of `f32`.
2020
/// Use [`f32::RADIX`](../../std/primitive.f32.html#associatedconstant.RADIX) instead.
21+
///
22+
/// # Examples
23+
///
24+
/// ```rust
25+
/// // deprecated way
26+
/// let r = std::f32::RADIX;
27+
///
28+
/// // correct way
29+
/// let r = f32::RADIX;
30+
/// ```
2131
#[stable(feature = "rust1", since = "1.0.0")]
2232
pub const RADIX: u32 = f32::RADIX;
2333

2434
/// Number of significant digits in base 2.
2535
/// Use [`f32::MANTISSA_DIGITS`](../../std/primitive.f32.html#associatedconstant.MANTISSA_DIGITS) instead.
36+
///
37+
/// # Examples
38+
///
39+
/// ```rust
40+
/// // deprecated way
41+
/// let d = std::f32::MANTISSA_DIGITS;
42+
///
43+
/// // correct way
44+
/// let d = f32::MANTISSA_DIGITS;
45+
/// ```
2646
#[stable(feature = "rust1", since = "1.0.0")]
2747
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
2848
/// Approximate number of significant digits in base 10.
2949
/// Use [`f32::DIGITS`](../../std/primitive.f32.html#associatedconstant.DIGITS) instead.
50+
///
51+
/// # Examples
52+
///
53+
/// ```rust
54+
/// // deprecated way
55+
/// let d = std::f32::DIGITS;
56+
///
57+
/// // correct way
58+
/// let d = f32::DIGITS;
59+
/// ```
3060
#[stable(feature = "rust1", since = "1.0.0")]
3161
pub const DIGITS: u32 = f32::DIGITS;
3262

@@ -36,50 +66,160 @@ pub const DIGITS: u32 = f32::DIGITS;
3666
/// This is the difference between `1.0` and the next larger representable number.
3767
///
3868
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
69+
///
70+
/// # Examples
71+
///
72+
/// ```rust
73+
/// // deprecated way
74+
/// let e = std::f32::EPSILON;
75+
///
76+
/// // correct way
77+
/// let e = f32::EPSILON;
78+
/// ```
3979
#[stable(feature = "rust1", since = "1.0.0")]
4080
pub const EPSILON: f32 = f32::EPSILON;
4181

4282
/// Smallest finite `f32` value.
4383
/// Use [`f32::MIN`](../../std/primitive.f32.html#associatedconstant.MIN) instead.
84+
///
85+
/// # Examples
86+
///
87+
/// ```rust
88+
/// // deprecated way
89+
/// let min = std::f32::MIN;
90+
///
91+
/// // correct way
92+
/// let min = f32::MIN;
93+
/// ```
4494
#[stable(feature = "rust1", since = "1.0.0")]
4595
pub const MIN: f32 = f32::MIN;
4696
/// Smallest positive normal `f32` value.
4797
/// Use [`f32::MIN_POSITIVE`](../../std/primitive.f32.html#associatedconstant.MIN_POSITIVE) instead.
98+
///
99+
/// # Examples
100+
///
101+
/// ```rust
102+
/// // deprecated way
103+
/// let min = std::f32::MIN_POSITIVE;
104+
///
105+
/// // correct way
106+
/// let min = f32::MIN_POSITIVE;
107+
/// ```
48108
#[stable(feature = "rust1", since = "1.0.0")]
49109
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
50110
/// Largest finite `f32` value.
51111
/// Use [`f32::MAX`](../../std/primitive.f32.html#associatedconstant.MAX) instead.
112+
///
113+
/// # Examples
114+
///
115+
/// ```rust
116+
/// // deprecated way
117+
/// let max = std::f32::MAX;
118+
///
119+
/// // correct way
120+
/// let max = f32::MAX;
121+
/// ```
52122
#[stable(feature = "rust1", since = "1.0.0")]
53123
pub const MAX: f32 = f32::MAX;
54124

55125
/// One greater than the minimum possible normal power of 2 exponent.
56126
/// Use [`f32::MIN_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_EXP) instead.
127+
///
128+
/// # Examples
129+
///
130+
/// ```rust
131+
/// // deprecated way
132+
/// let min = std::f32::MIN_EXP;
133+
///
134+
/// // correct way
135+
/// let min = f32::MIN_EXP;
136+
/// ```
57137
#[stable(feature = "rust1", since = "1.0.0")]
58138
pub const MIN_EXP: i32 = f32::MIN_EXP;
59139
/// Maximum possible power of 2 exponent.
60140
/// Use [`f32::MAX_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_EXP) instead.
141+
///
142+
/// # Examples
143+
///
144+
/// ```rust
145+
/// // deprecated way
146+
/// let max = std::f32::MAX_EXP;
147+
///
148+
/// // correct way
149+
/// let max = f32::MAX_EXP;
150+
/// ```
61151
#[stable(feature = "rust1", since = "1.0.0")]
62152
pub const MAX_EXP: i32 = f32::MAX_EXP;
63153

64154
/// Minimum possible normal power of 10 exponent.
65155
/// Use [`f32::MIN_10_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_10_EXP) instead.
156+
///
157+
/// # Examples
158+
///
159+
/// ```rust
160+
/// // deprecated way
161+
/// let min = std::f32::MIN_10_EXP;
162+
///
163+
/// // correct way
164+
/// let min = f32::MIN_10_EXP;
165+
/// ```
66166
#[stable(feature = "rust1", since = "1.0.0")]
67167
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
68168
/// Maximum possible power of 10 exponent.
69169
/// Use [`f32::MAX_10_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_10_EXP) instead.
170+
///
171+
/// # Examples
172+
///
173+
/// ```rust
174+
/// // deprecated way
175+
/// let max = std::f32::MAX_10_EXP;
176+
///
177+
/// // correct way
178+
/// let max = f32::MAX_10_EXP;
179+
/// ```
70180
#[stable(feature = "rust1", since = "1.0.0")]
71181
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
72182

73183
/// Not a Number (NaN).
74184
/// Use [`f32::NAN`](../../std/primitive.f32.html#associatedconstant.NAN) instead.
185+
///
186+
/// # Examples
187+
///
188+
/// ```rust
189+
/// // deprecated way
190+
/// let nan = std::f32::NAN;
191+
///
192+
/// // correct way
193+
/// let nan = f32::NAN;
194+
/// ```
75195
#[stable(feature = "rust1", since = "1.0.0")]
76196
pub const NAN: f32 = f32::NAN;
77197
/// Infinity (∞).
78198
/// Use [`f32::INFINITY`](../../std/primitive.f32.html#associatedconstant.INFINITY) instead.
199+
///
200+
/// # Examples
201+
///
202+
/// ```rust
203+
/// // deprecated way
204+
/// let inf = std::f32::INFINITY;
205+
///
206+
/// // correct way
207+
/// let inf = f32::INFINITY;
208+
/// ```
79209
#[stable(feature = "rust1", since = "1.0.0")]
80210
pub const INFINITY: f32 = f32::INFINITY;
81211
/// Negative infinity (−∞).
82212
/// Use [`f32::NEG_INFINITY`](../../std/primitive.f32.html#associatedconstant.NEG_INFINITY) instead.
213+
///
214+
/// # Examples
215+
///
216+
/// ```rust
217+
/// // deprecated way
218+
/// let ninf = std::f32::NEG_INFINITY;
219+
///
220+
/// // correct way
221+
/// let ninf = f32::NEG_INFINITY;
222+
/// ```
83223
#[stable(feature = "rust1", since = "1.0.0")]
84224
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;
85225

0 commit comments

Comments
 (0)