]> git.lizzy.rs Git - rust.git/blob - tests/ui/excessive_precision.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / excessive_precision.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::excessive_precision)]
11 #![allow(clippy::print_literal)]
12
13 fn main() {
14     // Consts
15     const GOOD32: f32 = 0.123_456;
16     const GOOD32_SM: f32 = 0.000_000_000_1;
17     const GOOD32_DOT: f32 = 10_000_000_000.0;
18     const GOOD32_EDGE: f32 = 1.000_000_8;
19     const GOOD64: f64 = 0.123_456_789_012;
20     const GOOD64_SM: f32 = 0.000_000_000_000_000_1;
21     const GOOD64_DOT: f32 = 10_000_000_000_000_000.0;
22
23     const BAD32_1: f32 = 0.123_456_789_f32;
24     const BAD32_2: f32 = 0.123_456_789;
25     const BAD32_3: f32 = 0.100_000_000_000_1;
26     const BAD32_EDGE: f32 = 1.000_000_9;
27
28     const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
29     const BAD64_2: f64 = 0.123_456_789_012_345_67;
30     const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
31
32     // Literal as param
33     println!("{:?}", 8.888_888_888_888_888_888_888);
34
35     // // TODO add inferred type tests for f32
36     // Locals
37     let good32: f32 = 0.123_456_f32;
38     let good32_2: f32 = 0.123_456;
39
40     let good64: f64 = 0.123_456_789_012;
41     let good64_suf: f64 = 0.123_456_789_012f64;
42     let good64_inf = 0.123_456_789_012;
43
44     let bad32: f32 = 1.123_456_789;
45     let bad32_suf: f32 = 1.123_456_789_f32;
46     let bad32_inf = 1.123_456_789_f32;
47
48     let bad64: f64 = 0.123_456_789_012_345_67;
49     let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
50     let bad64_inf = 0.123_456_789_012_345_67;
51
52     // Vectors
53     let good_vec32: Vec<f32> = vec![0.123_456];
54     let good_vec64: Vec<f64> = vec![0.123_456_789];
55
56     let bad_vec32: Vec<f32> = vec![0.123_456_789];
57     let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
58
59     // Exponential float notation
60     let good_e32: f32 = 1e-10;
61     let bad_e32: f32 = 1.123_456_788_888e-10;
62
63     let good_bige32: f32 = 1E-10;
64     let bad_bige32: f32 = 1.123_456_788_888E-10;
65
66     // Inferred type
67     let good_inferred: f32 = 1f32 * 1_000_000_000.;
68
69     // issue #2840
70     let num = 0.000_000_000_01e-10f64;
71 }