]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/floating_point_log.rs
Merge commit 'e228f0c16ea8c34794a6285bf57aab627c26b147' into libgccjit-codegen
[rust.git] / src / tools / clippy / tests / ui / floating_point_log.rs
1 // run-rustfix
2 #![allow(dead_code, clippy::double_parens)]
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.log(2f32);
11     let _ = x.log(10f32);
12     let _ = x.log(std::f32::consts::E);
13     let _ = x.log(TWO);
14     let _ = x.log(E);
15
16     let x = 1f64;
17     let _ = x.log(2f64);
18     let _ = x.log(10f64);
19     let _ = x.log(std::f64::consts::E);
20 }
21
22 fn check_ln1p() {
23     let x = 1f32;
24     let _ = (1f32 + 2.).ln();
25     let _ = (1f32 + 2.0).ln();
26     let _ = (1.0 + x).ln();
27     let _ = (1.0 + x / 2.0).ln();
28     let _ = (1.0 + x.powi(3)).ln();
29     let _ = (1.0 + x.powi(3) / 2.0).ln();
30     let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
31     let _ = (x + 1.0).ln();
32     let _ = (x.powi(3) + 1.0).ln();
33     let _ = (x + 2.0 + 1.0).ln();
34     let _ = (x / 2.0 + 1.0).ln();
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 _ = (1f64 + 2.).ln();
43     let _ = (1f64 + 2.0).ln();
44     let _ = (1.0 + x).ln();
45     let _ = (1.0 + x / 2.0).ln();
46     let _ = (1.0 + x.powi(3)).ln();
47     let _ = (x + 1.0).ln();
48     let _ = (x.powi(3) + 1.0).ln();
49     let _ = (x + 2.0 + 1.0).ln();
50     let _ = (x / 2.0 + 1.0).ln();
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() {}