2015-05-06 03:01:49 -05:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
use std::ops::Add;
|
|
|
|
|
|
|
|
const ZERO : f32 = 0.0;
|
|
|
|
const ONE : f32 = ZERO + 1.0;
|
|
|
|
|
|
|
|
fn twice<T>(x : T) -> T where T : Add<T, Output = T>, T : Copy {
|
2015-08-11 13:22:20 -05:00
|
|
|
x + x
|
2015-05-06 03:01:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(float_cmp)]
|
|
|
|
#[allow(unused)]
|
|
|
|
fn main() {
|
2015-08-17 05:06:56 -05:00
|
|
|
ZERO == 0f32; //no error, comparison with zero is ok
|
|
|
|
ZERO == 0.0; //no error, comparison with zero is ok
|
2015-08-13 01:12:07 -05:00
|
|
|
ZERO + ZERO != 1.0; //~ERROR !=-comparison of f32 or f64
|
2015-08-11 13:22:20 -05:00
|
|
|
|
2015-08-17 05:06:56 -05:00
|
|
|
ONE == 1f32; //~ERROR ==-comparison of f32 or f64
|
|
|
|
ONE == (1.0 + 0.0); //~ERROR ==-comparison of f32 or f64
|
|
|
|
|
|
|
|
ONE + ONE == (ZERO + ONE + ONE); //~ERROR ==-comparison of f32 or f64
|
|
|
|
|
|
|
|
ONE != 2.0; //~ERROR !=-comparison of f32 or f64
|
|
|
|
ONE != 0.0; // no error, comparison with zero is ok
|
2015-08-13 01:12:07 -05:00
|
|
|
twice(ONE) != ONE; //~ERROR !=-comparison of f32 or f64
|
2015-08-17 05:06:56 -05:00
|
|
|
ONE as f64 != 2.0; //~ERROR !=-comparison of f32 or f64
|
|
|
|
ONE as f64 != 0.0; // no error, comparison with zero is ok
|
2015-08-11 13:22:20 -05:00
|
|
|
|
|
|
|
let x : f64 = 1.0;
|
|
|
|
|
2015-08-13 01:12:07 -05:00
|
|
|
x == 1.0; //~ERROR ==-comparison of f32 or f64
|
2015-08-17 05:06:56 -05:00
|
|
|
x != 0f64; // no error, comparison with zero is ok
|
2015-08-11 13:22:20 -05:00
|
|
|
|
2015-08-13 01:12:07 -05:00
|
|
|
twice(x) != twice(ONE as f64); //~ERROR !=-comparison of f32 or f64
|
2015-08-11 13:22:20 -05:00
|
|
|
|
2015-08-17 05:06:56 -05:00
|
|
|
|
|
|
|
x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
|
2015-08-11 13:22:20 -05:00
|
|
|
x > 0.0;
|
|
|
|
x <= 0.0;
|
|
|
|
x >= 0.0;
|
2015-05-06 03:01:49 -05:00
|
|
|
}
|