1 #![feature(tool_lints)]
4 #![warn(clippy::float_cmp)]
5 #![allow(unused, clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
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
45 ONE + ONE == ZERO + ONE + ONE;
47 ONE != 0.0; // no error, comparison with zero is ok
50 ONE as f64 != 0.0; // no error, comparison with zero is ok
55 x != 0f64; // no error, comparison with zero is ok
57 twice(x) != twice(ONE as f64);
59 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
64 let xs : [f32; 1] = [0.0];
65 let a: *const f32 = xs.as_ptr();
66 let b: *const f32 = xs.as_ptr();
68 assert_eq!(a, b); // no errors