-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lint (x * x + y * y).sqrt() => x.hypot(y)
- Loading branch information
1 parent
808f9a1
commit 149c3ea
Showing
10 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// run-rustfix | ||
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] | ||
|
||
fn main() { | ||
let x = 3f32; | ||
let y = 4f32; | ||
let _ = x.hypot(y); | ||
let _ = (x + 1f32).hypot(y); | ||
let _ = x.hypot(y); | ||
// Cases where the lint shouldn't be applied | ||
let _ = x.mul_add(x, y * y).sqrt(); | ||
let _ = x.mul_add(4f32, y * y).sqrt(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// run-rustfix | ||
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] | ||
|
||
fn main() { | ||
let x = 3f32; | ||
let y = 4f32; | ||
let _ = (x * x + y * y).sqrt(); | ||
let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); | ||
let _ = (x.powi(2) + y.powi(2)).sqrt(); | ||
// Cases where the lint shouldn't be applied | ||
let _ = x.mul_add(x, y * y).sqrt(); | ||
let _ = (x * 4f32 + y * y).sqrt(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error: hypotenuse can be computed more accurately | ||
--> $DIR/floating_point_hypot.rs:7:13 | ||
| | ||
LL | let _ = (x * x + y * y).sqrt(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` | ||
| | ||
= note: `-D clippy::imprecise-flops` implied by `-D warnings` | ||
|
||
error: hypotenuse can be computed more accurately | ||
--> $DIR/floating_point_hypot.rs:8:13 | ||
| | ||
LL | let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 1f32).hypot(y)` | ||
|
||
error: hypotenuse can be computed more accurately | ||
--> $DIR/floating_point_hypot.rs:9:13 | ||
| | ||
LL | let _ = (x.powi(2) + y.powi(2)).sqrt(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` | ||
|
||
error: multiply and add expressions can be calculated more efficiently and accurately | ||
--> $DIR/floating_point_hypot.rs:12:13 | ||
| | ||
LL | let _ = (x * 4f32 + y * y).sqrt(); | ||
| ^^^^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(4f32, y * y)` | ||
| | ||
= note: `-D clippy::suboptimal-flops` implied by `-D warnings` | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
// run-rustfix | ||
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] | ||
#![warn(clippy::imprecise_flops)] | ||
|
||
fn main() { | ||
let one = 1; | ||
let x = 3f32; | ||
let _ = x * x; | ||
let _ = x * x; | ||
|
||
let y = 4f32; | ||
let _ = (x * x + y).sqrt(); | ||
let _ = (x + y * y).sqrt(); | ||
// Cases where the lint shouldn't be applied | ||
let _ = x.powi(3); | ||
let _ = x.powi(one + 1); | ||
let _ = x.hypot(y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
// run-rustfix | ||
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] | ||
#![warn(clippy::imprecise_flops)] | ||
|
||
fn main() { | ||
let one = 1; | ||
let x = 3f32; | ||
let _ = x.powi(2); | ||
let _ = x.powi(1 + 1); | ||
|
||
let y = 4f32; | ||
let _ = (x.powi(2) + y).sqrt(); | ||
let _ = (x + y.powi(2)).sqrt(); | ||
// Cases where the lint shouldn't be applied | ||
let _ = x.powi(3); | ||
let _ = x.powi(one + 1); | ||
let _ = (x.powi(2) + y.powi(2)).sqrt(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters