5 #![allow(unused, no_effect, unnecessary_operation)]
9 const ZERO : f32 = 0.0;
10 const ONE : f32 = ZERO + 1.0;
12 fn twice<T>(x : T) -> T where T : Add<T, Output = T>, T : Copy {
16 fn eq_fl(x: f32, y: f32) -> bool {
17 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
20 fn fl_eq(x: f32, y: f32) -> bool {
21 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
26 impl PartialEq for X {
27 fn eq(&self, o: &X) -> bool {
28 if self.val.is_nan() {
31 self.val == o.val // no error, inside "eq" fn
37 ZERO == 0f32; //no error, comparison with zero is ok
38 1.0f32 != ::std::f32::INFINITY; // also comparison with infinity
39 1.0f32 != ::std::f32::NEG_INFINITY; // and negative infinity
40 ZERO == 0.0; //no error, comparison with zero is ok
41 ZERO + ZERO != 1.0; //no error, comparison with zero is ok
44 //~^ ERROR strict comparison of f32 or f64
45 //~| HELP within some error
46 //~| SUGGESTION (ONE - 1f32).abs() < error
48 //~^ ERROR strict comparison of f32 or f64
49 //~| HELP within some error
50 //~| SUGGESTION (ONE - (1.0 + 0.0)).abs() < error
52 ONE + ONE == ZERO + ONE + ONE;
53 //~^ ERROR strict comparison of f32 or f64
54 //~| HELP within some error
55 //~| SUGGESTION (ONE + ONE - (ZERO + ONE + ONE)).abs() < error
58 //~^ ERROR strict comparison of f32 or f64
59 //~| HELP within some error
60 //~| SUGGESTION (ONE - 2.0).abs() < error
61 ONE != 0.0; // no error, comparison with zero is ok
63 //~^ ERROR strict comparison of f32 or f64
64 //~| HELP within some error
65 //~| SUGGESTION (twice(ONE) - ONE).abs() < error
67 //~^ ERROR strict comparison of f32 or f64
68 //~| HELP within some error
69 //~| SUGGESTION (ONE as f64 - 2.0).abs() < error
70 ONE as f64 != 0.0; // no error, comparison with zero is ok
75 //~^ ERROR strict comparison of f32 or f64
76 //~| HELP within some error
77 //~| SUGGESTION (x - 1.0).abs() < error
78 x != 0f64; // no error, comparison with zero is ok
80 twice(x) != twice(ONE as f64);
81 //~^ ERROR strict comparison of f32 or f64
82 //~| HELP within some error
83 //~| SUGGESTION (twice(x) - twice(ONE as f64)).abs() < error
86 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
91 let xs : [f32; 1] = [0.0];
92 let a: *const f32 = xs.as_ptr();
93 let b: *const f32 = xs.as_ptr();
95 assert!(a == b); // no errors