diff options
| author | bors <bors@rust-lang.org> | 2020-07-23 18:48:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-23 18:48:35 +0000 |
| commit | 79f948ec0a507f8dc663508ce013104847fcc9f3 (patch) | |
| tree | a307a9a64d4bdb626c9a9461b5a1b14ae0395f6a | |
| parent | b4e4fa51ea328adf5b182d3820dca9286d5ef3bf (diff) | |
| parent | 142a273441d1cf2039bd2857ee57cfa402e2a3f7 (diff) | |
| download | rust-79f948ec0a507f8dc663508ce013104847fcc9f3.tar.gz rust-79f948ec0a507f8dc663508ce013104847fcc9f3.zip | |
Auto merge of #5829 - JohnTitor:epsilon, r=flip1995
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
| -rw-r--r-- | clippy_lints/src/misc.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index fc10e5077b8..26a1c32b6b3 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -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 { } /// ``` @@ -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, |
