Commit 2734e4e
committed
Auto merge of #4897 - krishna-veerareddy:issue-2040-accurate-float-functions, r=flip1995
Add lint to improve floating-point expressions
Looks for floating-point expressions that can be expressed using built-in methods to improve accuracy, performance and/or succinctness.
changelog: Add lint `floating_point_improvements`.
Fixes #4726
Partly addresses [#2040](#2040)
Currently linted expressions:
| Expression | Suggestion |
|---------------------------------|------------|
| x.log(2.0) | x.log2() |
| x.log(10.0) | x.log10() |
| x.log(std::f32::consts::E) | x.ln() |
| (1 + x).ln() | x.ln_1p() |
| (2.0).powf(x) | x.exp2() |
| (std::f32::consts::E).powf(x) | x.exp() |
| x.powf(1/2) | x.sqrt() |
| x.powf(1/3) | x.cbrt() |
| x.powf(y), where y is whole | x.powi(y) |
| x.exp() - 1 | x.exp_m1() |
|x * y + z|x.mul_add(y, z)|File tree
23 files changed
+1092
-263
lines changed- clippy_lints/src
- src/lintlist
- tests/ui
23 files changed
+1092
-263
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1169 | 1169 | | |
1170 | 1170 | | |
1171 | 1171 | | |
| 1172 | + | |
1172 | 1173 | | |
1173 | 1174 | | |
1174 | 1175 | | |
| |||
1210 | 1211 | | |
1211 | 1212 | | |
1212 | 1213 | | |
1213 | | - | |
1214 | 1214 | | |
1215 | 1215 | | |
1216 | 1216 | | |
| |||
1349 | 1349 | | |
1350 | 1350 | | |
1351 | 1351 | | |
| 1352 | + | |
1352 | 1353 | | |
1353 | 1354 | | |
1354 | 1355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
0 commit comments