]> git.lizzy.rs Git - rust.git/blob - tests/ui/excessive_precision.rs
Merge pull request #3269 from rust-lang-nursery/relicense
[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
11 #![feature(tool_lints)]
12 #![warn(clippy::excessive_precision)]
13 #![allow(clippy::print_literal)]
14
15 fn main() {
16     // Consts
17     const GOOD32: f32 = 0.123_456;
18     const GOOD32_SM: f32 = 0.000_000_000_1;
19     const GOOD32_DOT: f32 = 10_000_000_000.0;
20     const GOOD32_EDGE: f32 = 1.000_000_8;
21     const GOOD64: f64 = 0.123_456_789_012;
22     const GOOD64_SM: f32 = 0.000_000_000_000_000_1;
23     const GOOD64_DOT: f32 = 10_000_000_000_000_000.0;
24
25     const BAD32_1: f32 = 0.123_456_789_f32;
26     const BAD32_2: f32 = 0.123_456_789;
27     const BAD32_3: f32 = 0.100_000_000_000_1;
28     const BAD32_EDGE: f32 = 1.000_000_9;
29
30     const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
31     const BAD64_2: f64 = 0.123_456_789_012_345_67;
32     const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
33
34     // Literal as param
35     println!("{:?}", 8.888_888_888_888_888_888_888);
36
37     // // TODO add inferred type tests for f32
38     // Locals
39     let good32: f32 = 0.123_456_f32;
40     let good32_2: f32 = 0.123_456;
41
42     let good64: f64 = 0.123_456_789_012;
43     let good64_suf: f64 = 0.123_456_789_012f64;
44     let good64_inf = 0.123_456_789_012;
45
46     let bad32: f32 = 1.123_456_789;
47     let bad32_suf: f32 = 1.123_456_789_f32;
48     let bad32_inf = 1.123_456_789_f32;
49
50     let bad64: f64 = 0.123_456_789_012_345_67;
51     let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
52     let bad64_inf = 0.123_456_789_012_345_67;
53
54     // Vectors
55     let good_vec32: Vec<f32> = vec![0.123_456];
56     let good_vec64: Vec<f64> = vec![0.123_456_789];
57
58     let bad_vec32: Vec<f32> = vec![0.123_456_789];
59     let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
60
61     // Exponential float notation
62     let good_e32: f32 = 1e-10;
63     let bad_e32: f32 = 1.123_456_788_888e-10;
64
65     let good_bige32: f32 = 1E-10;
66     let bad_bige32: f32 = 1.123_456_788_888E-10;
67
68     // Inferred type
69     let good_inferred: f32 = 1f32 * 1_000_000_000.;
70 }