2015-05-06 08:01:49 +00: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 18:22:20 +00:00
|
|
|
x + x
|
2015-05-06 08:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(float_cmp)]
|
|
|
|
#[allow(unused)]
|
|
|
|
fn main() {
|
2015-08-17 10:06:56 +00:00
|
|
|
ZERO == 0f32; //no error, comparison with zero is ok
|
|
|
|
ZERO == 0.0; //no error, comparison with zero is ok
|
2015-08-13 06:12:07 +00:00
|
|
|
ZERO + ZERO != 1.0; //~ERROR !=-comparison of f32 or f64
|
2015-08-11 18:22:20 +00:00
|
|
|
|
2015-08-17 10:06:56 +00: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 06:12:07 +00:00
|
|
|
twice(ONE) != ONE; //~ERROR !=-comparison of f32 or f64
|
2015-08-17 10:06:56 +00: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 18:22:20 +00:00
|
|
|
|
|
|
|
let x : f64 = 1.0;
|
|
|
|
|
2015-08-13 06:12:07 +00:00
|
|
|
x == 1.0; //~ERROR ==-comparison of f32 or f64
|
2015-08-17 10:06:56 +00:00
|
|
|
x != 0f64; // no error, comparison with zero is ok
|
2015-08-11 18:22:20 +00:00
|
|
|
|
2015-08-13 06:12:07 +00:00
|
|
|
twice(x) != twice(ONE as f64); //~ERROR !=-comparison of f32 or f64
|
2015-08-11 18:22:20 +00:00
|
|
|
|
2015-08-17 10:06:56 +00:00
|
|
|
|
|
|
|
x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
|
2015-08-11 18:22:20 +00:00
|
|
|
x > 0.0;
|
|
|
|
x <= 0.0;
|
|
|
|
x >= 0.0;
|
2015-05-06 08:01:49 +00:00
|
|
|
}
|