]> git.lizzy.rs Git - rust.git/blob - tests/ui/float_cmp_const.rs
remove duplicate tests with float_cmp
[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     // no errors, zero and infinity values
33     ONE != 0f32;
34     TWO == 0f32;
35     ONE != ::std::f32::INFINITY;
36     ONE == ::std::f32::NEG_INFINITY;
37
38     // Note: float_cmp will warn as expected on cases where there are no float constants
39     //       e.g. v == 1.0
40 }