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