mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 05:04:24 +00:00
Make use of existing constants.
f32::consts::PI / 2.0 -> f32::consts::FRAC_PI_2 f32::consts::PI / 4.0 -> f32::consts::FRAC_PI_4 f64::consts::PI / 2.0 -> f64::consts::FRAC_PI_2 f64::consts::PI / 4.0 -> f64::consts::FRAC_PI_4
This commit is contained in:
parent
3b04e91d27
commit
cdedd268d2
@ -600,7 +600,7 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let x = f32::consts::PI/2.0;
|
||||
/// let x = f32::consts::FRAC_PI_2;
|
||||
///
|
||||
/// let abs_difference = (x.sin() - 1.0).abs();
|
||||
///
|
||||
@ -646,7 +646,7 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let x = f32::consts::PI / 4.0;
|
||||
/// let x = f32::consts::FRAC_PI_4;
|
||||
/// let abs_difference = (x.tan() - 1.0).abs();
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
@ -666,10 +666,10 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let f = f32::consts::PI / 2.0;
|
||||
/// let f = f32::consts::FRAC_PI_2;
|
||||
///
|
||||
/// // asin(sin(pi/2))
|
||||
/// let abs_difference = (f.sin().asin() - f32::consts::PI / 2.0).abs();
|
||||
/// let abs_difference = (f.sin().asin() - f32::consts::FRAC_PI_2).abs();
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
@ -688,10 +688,10 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let f = f32::consts::PI / 4.0;
|
||||
/// let f = f32::consts::FRAC_PI_4;
|
||||
///
|
||||
/// // acos(cos(pi/4))
|
||||
/// let abs_difference = (f.cos().acos() - f32::consts::PI / 4.0).abs();
|
||||
/// let abs_difference = (f.cos().acos() - f32::consts::FRAC_PI_4).abs();
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
@ -734,7 +734,6 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let pi = f32::consts::PI;
|
||||
/// // Positive angles measured counter-clockwise
|
||||
/// // from positive x axis
|
||||
/// // -pi/4 radians (45 deg clockwise)
|
||||
@ -745,8 +744,8 @@ impl f32 {
|
||||
/// let x2 = -3.0f32;
|
||||
/// let y2 = 3.0f32;
|
||||
///
|
||||
/// let abs_difference_1 = (y1.atan2(x1) - (-pi / 4.0)).abs();
|
||||
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * pi / 4.0)).abs();
|
||||
/// 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();
|
||||
///
|
||||
/// assert!(abs_difference_1 <= f32::EPSILON);
|
||||
/// assert!(abs_difference_2 <= f32::EPSILON);
|
||||
@ -765,7 +764,7 @@ impl f32 {
|
||||
/// ```
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let x = f32::consts::PI/4.0;
|
||||
/// let x = f32::consts::FRAC_PI_4;
|
||||
/// let f = x.sin_cos();
|
||||
///
|
||||
/// let abs_difference_0 = (f.0 - x.sin()).abs();
|
||||
|
@ -537,7 +537,7 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let x = f64::consts::PI/2.0;
|
||||
/// let x = f64::consts::FRAC_PI_2;
|
||||
///
|
||||
/// let abs_difference = (x.sin() - 1.0).abs();
|
||||
///
|
||||
@ -575,7 +575,7 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let x = f64::consts::PI/4.0;
|
||||
/// let x = f64::consts::FRAC_PI_4;
|
||||
/// let abs_difference = (x.tan() - 1.0).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-14);
|
||||
@ -595,10 +595,10 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let f = f64::consts::PI / 2.0;
|
||||
/// let f = f64::consts::FRAC_PI_2;
|
||||
///
|
||||
/// // asin(sin(pi/2))
|
||||
/// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs();
|
||||
/// let abs_difference = (f.sin().asin() - f64::consts::FRAC_PI_2).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
@ -617,10 +617,10 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let f = f64::consts::PI / 4.0;
|
||||
/// let f = f64::consts::FRAC_PI_4;
|
||||
///
|
||||
/// // acos(cos(pi/4))
|
||||
/// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs();
|
||||
/// let abs_difference = (f.cos().acos() - f64::consts::FRAC_PI_4).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
@ -661,7 +661,6 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let pi = f64::consts::PI;
|
||||
/// // Positive angles measured counter-clockwise
|
||||
/// // from positive x axis
|
||||
/// // -pi/4 radians (45 deg clockwise)
|
||||
@ -672,8 +671,8 @@ impl f64 {
|
||||
/// let x2 = -3.0_f64;
|
||||
/// let y2 = 3.0_f64;
|
||||
///
|
||||
/// let abs_difference_1 = (y1.atan2(x1) - (-pi / 4.0)).abs();
|
||||
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * pi / 4.0)).abs();
|
||||
/// 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();
|
||||
///
|
||||
/// assert!(abs_difference_1 < 1e-10);
|
||||
/// assert!(abs_difference_2 < 1e-10);
|
||||
@ -692,7 +691,7 @@ impl f64 {
|
||||
/// ```
|
||||
/// use std::f64;
|
||||
///
|
||||
/// let x = f64::consts::PI/4.0;
|
||||
/// let x = f64::consts::FRAC_PI_4;
|
||||
/// let f = x.sin_cos();
|
||||
///
|
||||
/// let abs_difference_0 = (f.0 - x.sin()).abs();
|
||||
|
Loading…
Reference in New Issue
Block a user