]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/floating_point_log.fixed
Rollup merge of #102412 - joboet:dont_panic, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / floating_point_log.fixed
1 // run-rustfix
2 #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
3 #![warn(clippy::suboptimal_flops, clippy::imprecise_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     let _ = (x as f32).log2();
16
17     let x = 1f64;
18     let _ = x.log2();
19     let _ = x.log10();
20     let _ = x.ln();
21 }
22
23 fn check_ln1p() {
24     let x = 1f32;
25     let _ = 2.0f32.ln_1p();
26     let _ = 2.0f32.ln_1p();
27     let _ = x.ln_1p();
28     let _ = (x / 2.0).ln_1p();
29     let _ = x.powi(3).ln_1p();
30     let _ = (x.powi(3) / 2.0).ln_1p();
31     let _ = (std::f32::consts::E - 1.0).ln_1p();
32     let _ = x.ln_1p();
33     let _ = x.powi(3).ln_1p();
34     let _ = (x + 2.0).ln_1p();
35     let _ = (x / 2.0).ln_1p();
36     // Cases where the lint shouldn't be applied
37     let _ = (1.0 + x + 2.0).ln();
38     let _ = (x + 1.0 + 2.0).ln();
39     let _ = (x + 1.0 / 2.0).ln();
40     let _ = (1.0 + x - 2.0).ln();
41
42     let x = 1f64;
43     let _ = 2.0f64.ln_1p();
44     let _ = 2.0f64.ln_1p();
45     let _ = x.ln_1p();
46     let _ = (x / 2.0).ln_1p();
47     let _ = x.powi(3).ln_1p();
48     let _ = x.ln_1p();
49     let _ = x.powi(3).ln_1p();
50     let _ = (x + 2.0).ln_1p();
51     let _ = (x / 2.0).ln_1p();
52     // Cases where the lint shouldn't be applied
53     let _ = (1.0 + x + 2.0).ln();
54     let _ = (x + 1.0 + 2.0).ln();
55     let _ = (x + 1.0 / 2.0).ln();
56     let _ = (1.0 + x - 2.0).ln();
57 }
58
59 fn main() {}