Skip to content

Commit 454e505

Browse files
Run rust-fix on tests
1 parent bc706e3 commit 454e505

9 files changed

+205
-54
lines changed

tests/ui/floating_point_exp.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// run-rustfix
2+
#![warn(clippy::suboptimal_flops)]
3+
4+
fn main() {
5+
let x = 2f32;
6+
let _ = x.exp_m1();
7+
let _ = x.exp_m1() + 2.0;
8+
// Cases where the lint shouldn't be applied
9+
let _ = x.exp() - 2.0;
10+
let _ = x.exp() - 1.0 * 2.0;
11+
12+
let x = 2f64;
13+
let _ = x.exp_m1();
14+
let _ = x.exp_m1() + 2.0;
15+
// Cases where the lint shouldn't be applied
16+
let _ = x.exp() - 2.0;
17+
let _ = x.exp() - 1.0 * 2.0;
18+
}

tests/ui/floating_point_exp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
#![warn(clippy::suboptimal_flops)]
23

34
fn main() {

tests/ui/floating_point_exp.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: (e.pow(x) - 1) can be computed more accurately
2-
--> $DIR/floating_point_exp.rs:5:13
2+
--> $DIR/floating_point_exp.rs:6:13
33
|
44
LL | let _ = x.exp() - 1.0;
55
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
66
|
77
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
88

99
error: (e.pow(x) - 1) can be computed more accurately
10-
--> $DIR/floating_point_exp.rs:6:13
10+
--> $DIR/floating_point_exp.rs:7:13
1111
|
1212
LL | let _ = x.exp() - 1.0 + 2.0;
1313
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
1414

1515
error: (e.pow(x) - 1) can be computed more accurately
16-
--> $DIR/floating_point_exp.rs:12:13
16+
--> $DIR/floating_point_exp.rs:13:13
1717
|
1818
LL | let _ = x.exp() - 1.0;
1919
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
2020

2121
error: (e.pow(x) - 1) can be computed more accurately
22-
--> $DIR/floating_point_exp.rs:13:13
22+
--> $DIR/floating_point_exp.rs:14:13
2323
|
2424
LL | let _ = x.exp() - 1.0 + 2.0;
2525
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`

tests/ui/floating_point_log.fixed

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// run-rustfix
2+
#![allow(dead_code, clippy::double_parens)]
3+
#![warn(clippy::suboptimal_flops)]
4+
5+
const TWO: f32 = 2.0;
6+
const E: f32 = std::f32::consts::E;
7+
8+
fn check_log_base() {
9+
let x = 1f32;
10+
let _ = x.log2();
11+
let _ = x.log10();
12+
let _ = x.ln();
13+
let _ = x.log2();
14+
let _ = x.ln();
15+
16+
let x = 1f64;
17+
let _ = x.log2();
18+
let _ = x.log10();
19+
let _ = x.ln();
20+
}
21+
22+
fn check_ln1p() {
23+
let x = 1f32;
24+
let _ = 2.0f32.ln_1p();
25+
let _ = 2.0f32.ln_1p();
26+
let _ = x.ln_1p();
27+
let _ = (x * 2.0).ln_1p();
28+
let _ = x.powi(2).ln_1p();
29+
let _ = (x.powi(2) * 2.0).ln_1p();
30+
let _ = ((std::f32::consts::E - 1.0)).ln_1p();
31+
let _ = x.ln_1p();
32+
let _ = x.powi(2).ln_1p();
33+
let _ = (x + 2.0).ln_1p();
34+
let _ = (x * 2.0).ln_1p();
35+
// Cases where the lint shouldn't be applied
36+
let _ = (1.0 + x + 2.0).ln();
37+
let _ = (x + 1.0 + 2.0).ln();
38+
let _ = (x + 1.0 * 2.0).ln();
39+
let _ = (1.0 + x - 2.0).ln();
40+
41+
let x = 1f64;
42+
let _ = 2.0f64.ln_1p();
43+
let _ = 2.0f64.ln_1p();
44+
let _ = x.ln_1p();
45+
let _ = (x * 2.0).ln_1p();
46+
let _ = x.powi(2).ln_1p();
47+
let _ = x.ln_1p();
48+
let _ = x.powi(2).ln_1p();
49+
let _ = (x + 2.0).ln_1p();
50+
let _ = (x * 2.0).ln_1p();
51+
// Cases where the lint shouldn't be applied
52+
let _ = (1.0 + x + 2.0).ln();
53+
let _ = (x + 1.0 + 2.0).ln();
54+
let _ = (x + 1.0 * 2.0).ln();
55+
let _ = (1.0 + x - 2.0).ln();
56+
}
57+
58+
fn main() {}

tests/ui/floating_point_log.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![allow(dead_code)]
1+
// run-rustfix
2+
#![allow(dead_code, clippy::double_parens)]
23
#![warn(clippy::suboptimal_flops)]
34

45
const TWO: f32 = 2.0;

tests/ui/floating_point_log.stderr

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,169 @@
11
error: logarithm for bases 2, 10 and e can be computed more accurately
2-
--> $DIR/floating_point_log.rs:9:13
2+
--> $DIR/floating_point_log.rs:10:13
33
|
44
LL | let _ = x.log(2f32);
55
| ^^^^^^^^^^^ help: consider using: `x.log2()`
66
|
77
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
88

99
error: logarithm for bases 2, 10 and e can be computed more accurately
10-
--> $DIR/floating_point_log.rs:10:13
10+
--> $DIR/floating_point_log.rs:11:13
1111
|
1212
LL | let _ = x.log(10f32);
1313
| ^^^^^^^^^^^^ help: consider using: `x.log10()`
1414

1515
error: logarithm for bases 2, 10 and e can be computed more accurately
16-
--> $DIR/floating_point_log.rs:11:13
16+
--> $DIR/floating_point_log.rs:12:13
1717
|
1818
LL | let _ = x.log(std::f32::consts::E);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
2020

2121
error: logarithm for bases 2, 10 and e can be computed more accurately
22-
--> $DIR/floating_point_log.rs:12:13
22+
--> $DIR/floating_point_log.rs:13:13
2323
|
2424
LL | let _ = x.log(TWO);
2525
| ^^^^^^^^^^ help: consider using: `x.log2()`
2626

2727
error: logarithm for bases 2, 10 and e can be computed more accurately
28-
--> $DIR/floating_point_log.rs:13:13
28+
--> $DIR/floating_point_log.rs:14:13
2929
|
3030
LL | let _ = x.log(E);
3131
| ^^^^^^^^ help: consider using: `x.ln()`
3232

3333
error: logarithm for bases 2, 10 and e can be computed more accurately
34-
--> $DIR/floating_point_log.rs:16:13
34+
--> $DIR/floating_point_log.rs:17:13
3535
|
3636
LL | let _ = x.log(2f64);
3737
| ^^^^^^^^^^^ help: consider using: `x.log2()`
3838

3939
error: logarithm for bases 2, 10 and e can be computed more accurately
40-
--> $DIR/floating_point_log.rs:17:13
40+
--> $DIR/floating_point_log.rs:18:13
4141
|
4242
LL | let _ = x.log(10f64);
4343
| ^^^^^^^^^^^^ help: consider using: `x.log10()`
4444

4545
error: logarithm for bases 2, 10 and e can be computed more accurately
46-
--> $DIR/floating_point_log.rs:18:13
46+
--> $DIR/floating_point_log.rs:19:13
4747
|
4848
LL | let _ = x.log(std::f64::consts::E);
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
5050

5151
error: ln(1 + x) can be computed more accurately
52-
--> $DIR/floating_point_log.rs:23:13
52+
--> $DIR/floating_point_log.rs:24:13
5353
|
5454
LL | let _ = (1f32 + 2.).ln();
5555
| ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()`
5656

5757
error: ln(1 + x) can be computed more accurately
58-
--> $DIR/floating_point_log.rs:24:13
58+
--> $DIR/floating_point_log.rs:25:13
5959
|
6060
LL | let _ = (1f32 + 2.0).ln();
6161
| ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()`
6262

6363
error: ln(1 + x) can be computed more accurately
64-
--> $DIR/floating_point_log.rs:25:13
64+
--> $DIR/floating_point_log.rs:26:13
6565
|
6666
LL | let _ = (1.0 + x).ln();
6767
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
6868

6969
error: ln(1 + x) can be computed more accurately
70-
--> $DIR/floating_point_log.rs:26:13
70+
--> $DIR/floating_point_log.rs:27:13
7171
|
7272
LL | let _ = (1.0 + x * 2.0).ln();
7373
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
7474

7575
error: ln(1 + x) can be computed more accurately
76-
--> $DIR/floating_point_log.rs:27:13
76+
--> $DIR/floating_point_log.rs:28:13
7777
|
7878
LL | let _ = (1.0 + x.powi(2)).ln();
7979
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
8080

8181
error: ln(1 + x) can be computed more accurately
82-
--> $DIR/floating_point_log.rs:28:13
82+
--> $DIR/floating_point_log.rs:29:13
8383
|
8484
LL | let _ = (1.0 + x.powi(2) * 2.0).ln();
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(2) * 2.0).ln_1p()`
8686

8787
error: ln(1 + x) can be computed more accurately
88-
--> $DIR/floating_point_log.rs:29:13
88+
--> $DIR/floating_point_log.rs:30:13
8989
|
9090
LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `((std::f32::consts::E - 1.0)).ln_1p()`
9292

9393
error: ln(1 + x) can be computed more accurately
94-
--> $DIR/floating_point_log.rs:30:13
94+
--> $DIR/floating_point_log.rs:31:13
9595
|
9696
LL | let _ = (x + 1.0).ln();
9797
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
9898

9999
error: ln(1 + x) can be computed more accurately
100-
--> $DIR/floating_point_log.rs:31:13
100+
--> $DIR/floating_point_log.rs:32:13
101101
|
102102
LL | let _ = (x.powi(2) + 1.0).ln();
103103
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
104104

105105
error: ln(1 + x) can be computed more accurately
106-
--> $DIR/floating_point_log.rs:32:13
106+
--> $DIR/floating_point_log.rs:33:13
107107
|
108108
LL | let _ = (x + 2.0 + 1.0).ln();
109109
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()`
110110

111111
error: ln(1 + x) can be computed more accurately
112-
--> $DIR/floating_point_log.rs:33:13
112+
--> $DIR/floating_point_log.rs:34:13
113113
|
114114
LL | let _ = (x * 2.0 + 1.0).ln();
115115
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
116116

117117
error: ln(1 + x) can be computed more accurately
118-
--> $DIR/floating_point_log.rs:41:13
118+
--> $DIR/floating_point_log.rs:42:13
119119
|
120120
LL | let _ = (1f64 + 2.).ln();
121121
| ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()`
122122

123123
error: ln(1 + x) can be computed more accurately
124-
--> $DIR/floating_point_log.rs:42:13
124+
--> $DIR/floating_point_log.rs:43:13
125125
|
126126
LL | let _ = (1f64 + 2.0).ln();
127127
| ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()`
128128

129129
error: ln(1 + x) can be computed more accurately
130-
--> $DIR/floating_point_log.rs:43:13
130+
--> $DIR/floating_point_log.rs:44:13
131131
|
132132
LL | let _ = (1.0 + x).ln();
133133
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
134134

135135
error: ln(1 + x) can be computed more accurately
136-
--> $DIR/floating_point_log.rs:44:13
136+
--> $DIR/floating_point_log.rs:45:13
137137
|
138138
LL | let _ = (1.0 + x * 2.0).ln();
139139
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
140140

141141
error: ln(1 + x) can be computed more accurately
142-
--> $DIR/floating_point_log.rs:45:13
142+
--> $DIR/floating_point_log.rs:46:13
143143
|
144144
LL | let _ = (1.0 + x.powi(2)).ln();
145145
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
146146

147147
error: ln(1 + x) can be computed more accurately
148-
--> $DIR/floating_point_log.rs:46:13
148+
--> $DIR/floating_point_log.rs:47:13
149149
|
150150
LL | let _ = (x + 1.0).ln();
151151
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
152152

153153
error: ln(1 + x) can be computed more accurately
154-
--> $DIR/floating_point_log.rs:47:13
154+
--> $DIR/floating_point_log.rs:48:13
155155
|
156156
LL | let _ = (x.powi(2) + 1.0).ln();
157157
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
158158

159159
error: ln(1 + x) can be computed more accurately
160-
--> $DIR/floating_point_log.rs:48:13
160+
--> $DIR/floating_point_log.rs:49:13
161161
|
162162
LL | let _ = (x + 2.0 + 1.0).ln();
163163
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()`
164164

165165
error: ln(1 + x) can be computed more accurately
166-
--> $DIR/floating_point_log.rs:49:13
166+
--> $DIR/floating_point_log.rs:50:13
167167
|
168168
LL | let _ = (x * 2.0 + 1.0).ln();
169169
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`

tests/ui/floating_point_powf.fixed

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// run-rustfix
2+
#![warn(clippy::suboptimal_flops)]
3+
4+
fn main() {
5+
let x = 3f32;
6+
let _ = x.exp2();
7+
let _ = 3.1f32.exp2();
8+
let _ = (-3.1f32).exp2();
9+
let _ = x.exp();
10+
let _ = 3.1f32.exp();
11+
let _ = (-3.1f32).exp();
12+
let _ = x.sqrt();
13+
let _ = x.cbrt();
14+
let _ = x.powi(2);
15+
let _ = x.powi(-2);
16+
let _ = x.powi(16_777_215);
17+
let _ = x.powi(-16_777_215);
18+
let _ = x.powf(2.1);
19+
let _ = x.powf(-2.1);
20+
let _ = x.powf(16_777_216.0);
21+
let _ = x.powf(-16_777_216.0);
22+
23+
let x = 3f64;
24+
let _ = x.exp2();
25+
let _ = 3.1f64.exp2();
26+
let _ = (-3.1f64).exp2();
27+
let _ = x.exp();
28+
let _ = 3.1f64.exp();
29+
let _ = (-3.1f64).exp();
30+
let _ = x.sqrt();
31+
let _ = x.cbrt();
32+
let _ = x.powi(2);
33+
let _ = x.powi(-2);
34+
let _ = x.powi(-2_147_483_648);
35+
let _ = x.powi(2_147_483_647);
36+
let _ = x.powf(2.1);
37+
let _ = x.powf(-2.1);
38+
let _ = x.powf(-2_147_483_649.0);
39+
let _ = x.powf(2_147_483_648.0);
40+
}

tests/ui/floating_point_powf.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
#![warn(clippy::suboptimal_flops)]
23

34
fn main() {
@@ -12,8 +13,12 @@ fn main() {
1213
let _ = x.powf(1.0 / 3.0);
1314
let _ = x.powf(2.0);
1415
let _ = x.powf(-2.0);
16+
let _ = x.powf(16_777_215.0);
17+
let _ = x.powf(-16_777_215.0);
1518
let _ = x.powf(2.1);
1619
let _ = x.powf(-2.1);
20+
let _ = x.powf(16_777_216.0);
21+
let _ = x.powf(-16_777_216.0);
1722

1823
let x = 3f64;
1924
let _ = 2f64.powf(x);
@@ -26,6 +31,10 @@ fn main() {
2631
let _ = x.powf(1.0 / 3.0);
2732
let _ = x.powf(2.0);
2833
let _ = x.powf(-2.0);
34+
let _ = x.powf(-2_147_483_648.0);
35+
let _ = x.powf(2_147_483_647.0);
2936
let _ = x.powf(2.1);
3037
let _ = x.powf(-2.1);
38+
let _ = x.powf(-2_147_483_649.0);
39+
let _ = x.powf(2_147_483_648.0);
3140
}

0 commit comments

Comments
 (0)