Skip to content

Commit a60ae5d

Browse files
Split test cases into separate files
1 parent de79733 commit a60ae5d

6 files changed

+177
-167
lines changed

tests/ui/floating_point_exp.rs

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

tests/ui/floating_point_exp.stderr

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: (e.pow(x) - 1) can be computed more accurately
2+
--> $DIR/floating_point_exp.rs:5:13
3+
|
4+
LL | let _ = x.exp() - 1.0;
5+
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
6+
|
7+
= note: `-D clippy::floating-point-improvements` implied by `-D warnings`
8+
9+
error: (e.pow(x) - 1) can be computed more accurately
10+
--> $DIR/floating_point_exp.rs:6:13
11+
|
12+
LL | let _ = x.exp() - 1.0 + 2.0;
13+
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
14+
15+
error: (e.pow(x) - 1) can be computed more accurately
16+
--> $DIR/floating_point_exp.rs:12:13
17+
|
18+
LL | let _ = x.exp() - 1.0;
19+
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
20+
21+
error: (e.pow(x) - 1) can be computed more accurately
22+
--> $DIR/floating_point_exp.rs:13:13
23+
|
24+
LL | let _ = x.exp() - 1.0 + 2.0;
25+
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
26+
27+
error: aborting due to 4 previous errors
28+

tests/ui/floating_point_arithmetic.rs tests/ui/floating_point_log.rs

-42
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,6 @@ fn check_ln1p() {
4040
let _ = (1.0 + x - 2.0).ln();
4141
}
4242

43-
fn check_powf() {
44-
let x = 3f32;
45-
let _ = 2f32.powf(x);
46-
let _ = std::f32::consts::E.powf(x);
47-
let _ = x.powf(1.0 / 2.0);
48-
let _ = x.powf(1.0 / 3.0);
49-
let _ = x.powf(2.0);
50-
let _ = x.powf(-2.0);
51-
let _ = x.powf(2.1);
52-
let _ = x.powf(-2.1);
53-
let _ = x.powf(16_777_217.0);
54-
let _ = x.powf(-16_777_217.0);
55-
56-
let x = 3f64;
57-
let _ = 2f64.powf(x);
58-
let _ = std::f64::consts::E.powf(x);
59-
let _ = x.powf(1.0 / 2.0);
60-
let _ = x.powf(1.0 / 3.0);
61-
let _ = x.powf(2.0);
62-
let _ = x.powf(-2.0);
63-
let _ = x.powf(2.1);
64-
let _ = x.powf(-2.1);
65-
let _ = x.powf(9_007_199_254_740_993.0);
66-
let _ = x.powf(-9_007_199_254_740_993.0);
67-
}
68-
69-
fn check_expm1() {
70-
let x = 2f32;
71-
let _ = x.exp() - 1.0;
72-
let _ = x.exp() - 1.0 + 2.0;
73-
// Cases where the lint shouldn't be applied
74-
let _ = x.exp() - 2.0;
75-
let _ = x.exp() - 1.0 * 2.0;
76-
77-
let x = 2f64;
78-
let _ = x.exp() - 1.0;
79-
let _ = x.exp() - 1.0 + 2.0;
80-
// Cases where the lint shouldn't be applied
81-
let _ = x.exp() - 2.0;
82-
let _ = x.exp() - 1.0 * 2.0;
83-
}
84-
8543
fn check_log_division() {
8644
let x = 3f32;
8745
let y = 2f32;
Original file line numberDiff line numberDiff line change
@@ -1,268 +1,172 @@
11
error: logarithm for bases 2, 10 and e can be computed more accurately
2-
--> $DIR/floating_point_arithmetic.rs:9:13
2+
--> $DIR/floating_point_log.rs:9:13
33
|
44
LL | let _ = x.log(2f32);
55
| ^^^^^^^^^^^ help: consider using: `x.log2()`
66
|
77
= note: `-D clippy::floating-point-improvements` implied by `-D warnings`
88

99
error: logarithm for bases 2, 10 and e can be computed more accurately
10-
--> $DIR/floating_point_arithmetic.rs:10:13
10+
--> $DIR/floating_point_log.rs:10: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_arithmetic.rs:11:13
16+
--> $DIR/floating_point_log.rs:11: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_arithmetic.rs:12:13
22+
--> $DIR/floating_point_log.rs:12: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_arithmetic.rs:13:13
28+
--> $DIR/floating_point_log.rs:13: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_arithmetic.rs:16:13
34+
--> $DIR/floating_point_log.rs:16: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_arithmetic.rs:17:13
40+
--> $DIR/floating_point_log.rs:17: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_arithmetic.rs:18:13
46+
--> $DIR/floating_point_log.rs:18: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_arithmetic.rs:23:13
52+
--> $DIR/floating_point_log.rs:23:13
5353
|
5454
LL | let _ = (1.0 + x).ln();
5555
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
5656

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

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

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

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

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

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

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

99-
error: exponent for bases 2 and e can be computed more accurately
100-
--> $DIR/floating_point_arithmetic.rs:45:13
101-
|
102-
LL | let _ = 2f32.powf(x);
103-
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
104-
105-
error: exponent for bases 2 and e can be computed more accurately
106-
--> $DIR/floating_point_arithmetic.rs:46:13
107-
|
108-
LL | let _ = std::f32::consts::E.powf(x);
109-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
110-
111-
error: square-root of a number can be computed more efficiently and accurately
112-
--> $DIR/floating_point_arithmetic.rs:47:13
113-
|
114-
LL | let _ = x.powf(1.0 / 2.0);
115-
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
116-
117-
error: cube-root of a number can be computed more accurately
118-
--> $DIR/floating_point_arithmetic.rs:48:13
119-
|
120-
LL | let _ = x.powf(1.0 / 3.0);
121-
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
122-
123-
error: exponentiation with integer powers can be computed more efficiently
124-
--> $DIR/floating_point_arithmetic.rs:49:13
125-
|
126-
LL | let _ = x.powf(2.0);
127-
| ^^^^^^^^^^^ help: consider using: `x.powi(2)`
128-
129-
error: exponentiation with integer powers can be computed more efficiently
130-
--> $DIR/floating_point_arithmetic.rs:50:13
131-
|
132-
LL | let _ = x.powf(-2.0);
133-
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
134-
135-
error: exponent for bases 2 and e can be computed more accurately
136-
--> $DIR/floating_point_arithmetic.rs:57:13
137-
|
138-
LL | let _ = 2f64.powf(x);
139-
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
140-
141-
error: exponent for bases 2 and e can be computed more accurately
142-
--> $DIR/floating_point_arithmetic.rs:58:13
143-
|
144-
LL | let _ = std::f64::consts::E.powf(x);
145-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
146-
147-
error: square-root of a number can be computed more efficiently and accurately
148-
--> $DIR/floating_point_arithmetic.rs:59:13
149-
|
150-
LL | let _ = x.powf(1.0 / 2.0);
151-
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
152-
153-
error: cube-root of a number can be computed more accurately
154-
--> $DIR/floating_point_arithmetic.rs:60:13
155-
|
156-
LL | let _ = x.powf(1.0 / 3.0);
157-
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
158-
159-
error: exponentiation with integer powers can be computed more efficiently
160-
--> $DIR/floating_point_arithmetic.rs:61:13
161-
|
162-
LL | let _ = x.powf(2.0);
163-
| ^^^^^^^^^^^ help: consider using: `x.powi(2)`
164-
165-
error: exponentiation with integer powers can be computed more efficiently
166-
--> $DIR/floating_point_arithmetic.rs:62:13
167-
|
168-
LL | let _ = x.powf(-2.0);
169-
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
170-
171-
error: (e.pow(x) - 1) can be computed more accurately
172-
--> $DIR/floating_point_arithmetic.rs:71:13
173-
|
174-
LL | let _ = x.exp() - 1.0;
175-
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
176-
177-
error: (e.pow(x) - 1) can be computed more accurately
178-
--> $DIR/floating_point_arithmetic.rs:72:13
179-
|
180-
LL | let _ = x.exp() - 1.0 + 2.0;
181-
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
182-
183-
error: (e.pow(x) - 1) can be computed more accurately
184-
--> $DIR/floating_point_arithmetic.rs:78:13
185-
|
186-
LL | let _ = x.exp() - 1.0;
187-
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
188-
189-
error: (e.pow(x) - 1) can be computed more accurately
190-
--> $DIR/floating_point_arithmetic.rs:79:13
191-
|
192-
LL | let _ = x.exp() - 1.0 + 2.0;
193-
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
194-
19599
error: x.log(b) / y.log(b) can be reduced to x.log(y)
196-
--> $DIR/floating_point_arithmetic.rs:90:13
100+
--> $DIR/floating_point_log.rs:48:13
197101
|
198102
LL | let _ = x.log2() / y.log2();
199103
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
200104

201105
error: x.log(b) / y.log(b) can be reduced to x.log(y)
202-
--> $DIR/floating_point_arithmetic.rs:91:13
106+
--> $DIR/floating_point_log.rs:49:13
203107
|
204108
LL | let _ = x.log10() / y.log10();
205109
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
206110

207111
error: x.log(b) / y.log(b) can be reduced to x.log(y)
208-
--> $DIR/floating_point_arithmetic.rs:92:13
112+
--> $DIR/floating_point_log.rs:50:13
209113
|
210114
LL | let _ = x.ln() / y.ln();
211115
| ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
212116

213117
error: x.log(b) / y.log(b) can be reduced to x.log(y)
214-
--> $DIR/floating_point_arithmetic.rs:93:13
118+
--> $DIR/floating_point_log.rs:51:13
215119
|
216120
LL | let _ = x.log(4.0) / y.log(4.0);
217121
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
218122

219123
error: x.log(b) / y.log(b) can be reduced to x.log(y)
220-
--> $DIR/floating_point_arithmetic.rs:94:13
124+
--> $DIR/floating_point_log.rs:52:13
221125
|
222126
LL | let _ = x.log(b) / y.log(b);
223127
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
224128

225129
error: x.log(b) / y.log(b) can be reduced to x.log(y)
226-
--> $DIR/floating_point_arithmetic.rs:96:13
130+
--> $DIR/floating_point_log.rs:54:13
227131
|
228132
LL | let _ = x.log(b) / 2f32.log(b);
229133
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
230134

231135
error: x.log(b) / y.log(b) can be reduced to x.log(y)
232-
--> $DIR/floating_point_arithmetic.rs:102:13
136+
--> $DIR/floating_point_log.rs:60:13
233137
|
234138
LL | let _ = x.log2() / y.log2();
235139
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
236140

237141
error: x.log(b) / y.log(b) can be reduced to x.log(y)
238-
--> $DIR/floating_point_arithmetic.rs:103:13
142+
--> $DIR/floating_point_log.rs:61:13
239143
|
240144
LL | let _ = x.log10() / y.log10();
241145
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
242146

243147
error: x.log(b) / y.log(b) can be reduced to x.log(y)
244-
--> $DIR/floating_point_arithmetic.rs:104:13
148+
--> $DIR/floating_point_log.rs:62:13
245149
|
246150
LL | let _ = x.ln() / y.ln();
247151
| ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
248152

249153
error: x.log(b) / y.log(b) can be reduced to x.log(y)
250-
--> $DIR/floating_point_arithmetic.rs:105:13
154+
--> $DIR/floating_point_log.rs:63:13
251155
|
252156
LL | let _ = x.log(4.0) / y.log(4.0);
253157
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
254158

255159
error: x.log(b) / y.log(b) can be reduced to x.log(y)
256-
--> $DIR/floating_point_arithmetic.rs:106:13
160+
--> $DIR/floating_point_log.rs:64:13
257161
|
258162
LL | let _ = x.log(b) / y.log(b);
259163
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
260164

261165
error: x.log(b) / y.log(b) can be reduced to x.log(y)
262-
--> $DIR/floating_point_arithmetic.rs:108:13
166+
--> $DIR/floating_point_log.rs:66:13
263167
|
264168
LL | let _ = x.log(b) / 2f64.log(b);
265169
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
266170

267-
error: aborting due to 44 previous errors
171+
error: aborting due to 28 previous errors
268172

0 commit comments

Comments
 (0)