Skip to content

Commit

Permalink
Remove more std::f32 imports in libstd
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Apr 5, 2020
1 parent d06b26f commit daf8afd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 78 deletions.
54 changes: 15 additions & 39 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let x = f32::consts::FRAC_PI_2;
/// let x = std::f32::consts::FRAC_PI_2;
///
/// let abs_difference = (x.sin() - 1.0).abs();
///
Expand All @@ -566,9 +564,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let x = 2.0 * f32::consts::PI;
/// let x = 2.0 * std::f32::consts::PI;
///
/// let abs_difference = (x.cos() - 1.0).abs();
///
Expand All @@ -586,9 +582,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let x = f32::consts::FRAC_PI_4;
/// let x = std::f32::consts::FRAC_PI_4;
/// let abs_difference = (x.tan() - 1.0).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
Expand All @@ -607,12 +601,10 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let f = f32::consts::FRAC_PI_2;
/// let f = std::f32::consts::FRAC_PI_2;
///
/// // asin(sin(pi/2))
/// let abs_difference = (f.sin().asin() - f32::consts::FRAC_PI_2).abs();
/// let abs_difference = (f.sin().asin() - std::f32::consts::FRAC_PI_2).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
Expand All @@ -630,12 +622,10 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let f = f32::consts::FRAC_PI_4;
/// let f = std::f32::consts::FRAC_PI_4;
///
/// // acos(cos(pi/4))
/// let abs_difference = (f.cos().acos() - f32::consts::FRAC_PI_4).abs();
/// let abs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
Expand Down Expand Up @@ -676,8 +666,6 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// // Positive angles measured counter-clockwise
/// // from positive x axis
/// // -pi/4 radians (45 deg clockwise)
Expand All @@ -688,8 +676,8 @@ impl f32 {
/// let x2 = -3.0f32;
/// let y2 = 3.0f32;
///
/// let abs_difference_1 = (y1.atan2(x1) - (-f32::consts::FRAC_PI_4)).abs();
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f32::consts::FRAC_PI_4)).abs();
/// let abs_difference_1 = (y1.atan2(x1) - (-std::f32::consts::FRAC_PI_4)).abs();
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f32::consts::FRAC_PI_4)).abs();
///
/// assert!(abs_difference_1 <= f32::EPSILON);
/// assert!(abs_difference_2 <= f32::EPSILON);
Expand All @@ -707,9 +695,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let x = f32::consts::FRAC_PI_4;
/// let x = std::f32::consts::FRAC_PI_4;
/// let f = x.sin_cos();
///
/// let abs_difference_0 = (f.0 - x.sin()).abs();
Expand Down Expand Up @@ -750,9 +736,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let x = f32::consts::E - 1.0;
/// let x = std::f32::consts::E - 1.0;
///
/// // ln(1 + (e - 1)) == ln(e) == 1
/// let abs_difference = (x.ln_1p() - 1.0).abs();
Expand All @@ -771,9 +755,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let e = f32::consts::E;
/// let e = std::f32::consts::E;
/// let x = 1.0f32;
///
/// let f = x.sinh();
Expand All @@ -795,9 +777,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let e = f32::consts::E;
/// let e = std::f32::consts::E;
/// let x = 1.0f32;
/// let f = x.cosh();
/// // Solving cosh() at 1 gives this result
Expand All @@ -819,9 +799,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let e = f32::consts::E;
/// let e = std::f32::consts::E;
/// let x = 1.0f32;
///
/// let f = x.tanh();
Expand Down Expand Up @@ -885,9 +863,7 @@ impl f32 {
/// # Examples
///
/// ```
/// use std::f32;
///
/// let e = f32::consts::E;
/// let e = std::f32::consts::E;
/// let f = e.tanh().atanh();
///
/// let abs_difference = (f - e).abs();
Expand Down
54 changes: 15 additions & 39 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let x = f64::consts::FRAC_PI_2;
/// let x = std::f64::consts::FRAC_PI_2;
///
/// let abs_difference = (x.sin() - 1.0).abs();
///
Expand All @@ -568,9 +566,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let x = 2.0 * f64::consts::PI;
/// let x = 2.0 * std::f64::consts::PI;
///
/// let abs_difference = (x.cos() - 1.0).abs();
///
Expand All @@ -588,9 +584,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let x = f64::consts::FRAC_PI_4;
/// let x = std::f64::consts::FRAC_PI_4;
/// let abs_difference = (x.tan() - 1.0).abs();
///
/// assert!(abs_difference < 1e-14);
Expand All @@ -609,12 +603,10 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let f = f64::consts::FRAC_PI_2;
/// let f = std::f64::consts::FRAC_PI_2;
///
/// // asin(sin(pi/2))
/// let abs_difference = (f.sin().asin() - f64::consts::FRAC_PI_2).abs();
/// let abs_difference = (f.sin().asin() - std::f64::consts::FRAC_PI_2).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
Expand All @@ -632,12 +624,10 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let f = f64::consts::FRAC_PI_4;
/// let f = std::f64::consts::FRAC_PI_4;
///
/// // acos(cos(pi/4))
/// let abs_difference = (f.cos().acos() - f64::consts::FRAC_PI_4).abs();
/// let abs_difference = (f.cos().acos() - std::f64::consts::FRAC_PI_4).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
Expand Down Expand Up @@ -678,8 +668,6 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// // Positive angles measured counter-clockwise
/// // from positive x axis
/// // -pi/4 radians (45 deg clockwise)
Expand All @@ -690,8 +678,8 @@ impl f64 {
/// let x2 = -3.0_f64;
/// let y2 = 3.0_f64;
///
/// let abs_difference_1 = (y1.atan2(x1) - (-f64::consts::FRAC_PI_4)).abs();
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f64::consts::FRAC_PI_4)).abs();
/// let abs_difference_1 = (y1.atan2(x1) - (-std::f64::consts::FRAC_PI_4)).abs();
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f64::consts::FRAC_PI_4)).abs();
///
/// assert!(abs_difference_1 < 1e-10);
/// assert!(abs_difference_2 < 1e-10);
Expand All @@ -709,9 +697,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let x = f64::consts::FRAC_PI_4;
/// let x = std::f64::consts::FRAC_PI_4;
/// let f = x.sin_cos();
///
/// let abs_difference_0 = (f.0 - x.sin()).abs();
Expand Down Expand Up @@ -752,9 +738,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let x = f64::consts::E - 1.0;
/// let x = std::f64::consts::E - 1.0;
///
/// // ln(1 + (e - 1)) == ln(e) == 1
/// let abs_difference = (x.ln_1p() - 1.0).abs();
Expand All @@ -773,9 +757,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let e = f64::consts::E;
/// let e = std::f64::consts::E;
/// let x = 1.0_f64;
///
/// let f = x.sinh();
Expand All @@ -797,9 +779,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let e = f64::consts::E;
/// let e = std::f64::consts::E;
/// let x = 1.0_f64;
/// let f = x.cosh();
/// // Solving cosh() at 1 gives this result
Expand All @@ -821,9 +801,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let e = f64::consts::E;
/// let e = std::f64::consts::E;
/// let x = 1.0_f64;
///
/// let f = x.tanh();
Expand Down Expand Up @@ -887,9 +865,7 @@ impl f64 {
/// # Examples
///
/// ```
/// use std::f64;
///
/// let e = f64::consts::E;
/// let e = std::f64::consts::E;
/// let f = e.tanh().atanh();
///
/// let abs_difference = (f - e).abs();
Expand Down

0 comments on commit daf8afd

Please sign in to comment.