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:
Tomasz Różański 2019-08-22 14:59:31 +02:00
parent 3b04e91d27
commit cdedd268d2
2 changed files with 18 additions and 20 deletions

View File

@ -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();

View File

@ -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();