Skip to content

Commit f153125

Browse files
committed
Use the correct types in float examples
1 parent e41cdab commit f153125

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

src/libstd/num/f32.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl f32 {
217217
/// // Values between `0` and `min` are Subnormal.
218218
/// assert!(!lower_than_min.is_normal());
219219
/// ```
220-
/// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number
220+
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
221221
#[stable(feature = "rust1", since = "1.0.0")]
222222
#[inline]
223223
pub fn is_normal(self) -> bool { num::Float::is_normal(self) }
@@ -923,12 +923,12 @@ impl f32 {
923923
/// Computes the tangent of a number (in radians).
924924
///
925925
/// ```
926-
/// use std::f64;
926+
/// use std::f32;
927927
///
928-
/// let x = f64::consts::PI/4.0;
928+
/// let x = f32::consts::PI / 4.0;
929929
/// let abs_difference = (x.tan() - 1.0).abs();
930930
///
931-
/// assert!(abs_difference < 1e-10);
931+
/// assert!(abs_difference <= f32::EPSILON);
932932
/// ```
933933
#[stable(feature = "rust1", since = "1.0.0")]
934934
#[inline]
@@ -1052,12 +1052,14 @@ impl f32 {
10521052
/// number is close to zero.
10531053
///
10541054
/// ```
1055-
/// let x = 7.0f64;
1055+
/// use std::f32;
10561056
///
1057-
/// // e^(ln(7)) - 1
1058-
/// let abs_difference = (x.ln().exp_m1() - 6.0).abs();
1057+
/// let x = 6.0f32;
10591058
///
1060-
/// assert!(abs_difference < 1e-10);
1059+
/// // e^(ln(6)) - 1
1060+
/// let abs_difference = (x.ln().exp_m1() - 5.0).abs();
1061+
///
1062+
/// assert!(abs_difference <= f32::EPSILON);
10611063
/// ```
10621064
#[stable(feature = "rust1", since = "1.0.0")]
10631065
#[inline]

src/libstd/num/f64.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ impl f64 {
147147
/// [subnormal][subnormal], or `NaN`.
148148
///
149149
/// ```
150-
/// use std::f32;
150+
/// use std::f64;
151151
///
152-
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f64
153-
/// let max = f32::MAX;
154-
/// let lower_than_min = 1.0e-40_f32;
155-
/// let zero = 0.0f32;
152+
/// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308f64
153+
/// let max = f64::MAX;
154+
/// let lower_than_min = 1.0e-308_f64;
155+
/// let zero = 0.0f64;
156156
///
157157
/// assert!(min.is_normal());
158158
/// assert!(max.is_normal());
159159
///
160160
/// assert!(!zero.is_normal());
161-
/// assert!(!f32::NAN.is_normal());
162-
/// assert!(!f32::INFINITY.is_normal());
161+
/// assert!(!f64::NAN.is_normal());
162+
/// assert!(!f64::INFINITY.is_normal());
163163
/// // Values between `0` and `min` are Subnormal.
164164
/// assert!(!lower_than_min.is_normal());
165165
/// ```
166-
/// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number
166+
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
167167
#[stable(feature = "rust1", since = "1.0.0")]
168168
#[inline]
169169
pub fn is_normal(self) -> bool { num::Float::is_normal(self) }
@@ -655,9 +655,9 @@ impl f64 {
655655
/// ```
656656
/// #![feature(float_extras)]
657657
///
658-
/// let x = 1.0f32;
658+
/// let x = 1.0f64;
659659
///
660-
/// let abs_diff = (x.next_after(2.0) - 1.00000011920928955078125_f32).abs();
660+
/// let abs_diff = (x.next_after(2.0) - 1.0000000000000002220446049250313_f64).abs();
661661
///
662662
/// assert!(abs_diff < 1e-10);
663663
/// ```

src/libstd/primitive_docs.rs

-6
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,6 @@ mod prim_tuple { }
490490
///
491491
/// *[See also the `std::f32` module](f32/index.html).*
492492
///
493-
/// However, please note that examples are shared between the `f64` and `f32`
494-
/// primitive types. So it's normal if you see usage of `f64` in there.
495-
///
496493
mod prim_f32 { }
497494

498495
#[doc(primitive = "f64")]
@@ -501,9 +498,6 @@ mod prim_f32 { }
501498
///
502499
/// *[See also the `std::f64` module](f64/index.html).*
503500
///
504-
/// However, please note that examples are shared between the `f64` and `f32`
505-
/// primitive types. So it's normal if you see usage of `f32` in there.
506-
///
507501
mod prim_f64 { }
508502

509503
#[doc(primitive = "i8")]

0 commit comments

Comments
 (0)