]> git.lizzy.rs Git - rust.git/blob - tests/ui/float_cmp_const.rs
Merge pull request #2984 from flip1995/single_char_pattern
[rust.git] / tests / ui / float_cmp_const.rs
1
2
3
4 #![warn(float_cmp_const)]
5 #![allow(float_cmp)]
6 #![allow(unused, no_effect, unnecessary_operation)]
7
8 const ONE: f32 = 1.0;
9 const TWO: f32 = 2.0;
10
11 fn eq_one(x: f32) -> bool {
12     if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn
13 }
14
15 fn main() {
16     // has errors
17     1f32 == ONE;
18     TWO == ONE;
19     TWO != ONE;
20     ONE + ONE == TWO;
21     1 as f32 == ONE;
22
23     let v = 0.9;
24     v == ONE;
25     v != ONE;
26
27     // no errors, lower than or greater than comparisons
28     v < ONE;
29     v > ONE;
30     v <= ONE;
31     v >= ONE;
32
33     // no errors, zero and infinity values
34     ONE != 0f32;
35     TWO == 0f32;
36     ONE != ::std::f32::INFINITY;
37     ONE == ::std::f32::NEG_INFINITY;
38
39     // no errors, but will warn float_cmp if '#![allow(float_cmp)]' above is removed
40     let w = 1.1;
41     v == w;
42     v != w;
43     v == 1.0;
44     v != 1.0;
45 }