Skip to content

Commit 79f948e

Browse files
committed
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
2 parents b4e4fa5 + 142a273 commit 79f948e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clippy_lints/src/misc.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ declare_clippy_lint! {
9999
/// if y != x {} // where both are floats
100100
///
101101
/// // Good
102-
/// let error = 0.01f64; // Use an epsilon for comparison
102+
/// let error = f64::EPSILON; // Use an epsilon for comparison
103+
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
104+
/// // let error = std::f64::EPSILON;
103105
/// if (y - 1.23f64).abs() < error { }
104106
/// if (y - x).abs() > error { }
105107
/// ```
@@ -237,10 +239,12 @@ declare_clippy_lint! {
237239
/// const ONE: f64 = 1.00;
238240
///
239241
/// // Bad
240-
/// if x == ONE { } // where both are floats
242+
/// if x == ONE { } // where both are floats
241243
///
242244
/// // Good
243-
/// let error = 0.1f64; // Use an epsilon for comparison
245+
/// let error = f64::EPSILON; // Use an epsilon for comparison
246+
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
247+
/// // let error = std::f64::EPSILON;
244248
/// if (x - ONE).abs() < error { }
245249
/// ```
246250
pub FLOAT_CMP_CONST,

0 commit comments

Comments
 (0)