Skip to content

Commit

Permalink
Auto merge of #5829 - JohnTitor:epsilon, r=flip1995
Browse files Browse the repository at this point in the history
Use `(std::)f64::EPSILON` in the examples as suggested in the lints

`float_cmp(_const)` suggests using `{f32|f64}::EPSILON` and it'd be great if the docs mentioned it.

changelog: none
  • Loading branch information
bors committed Jul 22, 2020
2 parents 8c83d5f + 142a273 commit 42c7d75
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ declare_clippy_lint! {
/// if y != x {} // where both are floats
///
/// // Good
/// let error = 0.01f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (y - 1.23f64).abs() < error { }
/// if (y - x).abs() > error { }
/// ```
Expand Down Expand Up @@ -237,10 +239,12 @@ declare_clippy_lint! {
/// const ONE: f64 = 1.00;
///
/// // Bad
/// if x == ONE { } // where both are floats
/// if x == ONE { } // where both are floats
///
/// // Good
/// let error = 0.1f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (x - ONE).abs() < error { }
/// ```
pub FLOAT_CMP_CONST,
Expand Down

0 comments on commit 42c7d75

Please sign in to comment.