Fix float comparison bug found by clippy

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-07-26 22:52:03 +02:00 committed by Matthias Beyer
parent 2c26fd2753
commit 8469fd5596

View file

@ -66,6 +66,8 @@ use toml_query::read::TomlValueReadExt;
mod ui; mod ui;
const EPS_CMP: f64 = 1e-10;
fn main() { fn main() {
let version = make_imag_version!(); let version = make_imag_version!();
let rt = generate_runtime_setup("imag-header", let rt = generate_runtime_setup("imag-header",
@ -254,10 +256,10 @@ fn float<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> i32
let filter = ::filters::ops::bool::Bool::new(true) let filter = ::filters::ops::bool::Bool::new(true)
.and(|i: &f64| -> bool { .and(|i: &f64| -> bool {
implement_compare!(mtch, "header-float-eq", f64, |cmp| *i == cmp) implement_compare!(mtch, "header-float-eq", f64, |cmp: f64| (*i - cmp).abs() < EPS_CMP)
}) })
.and(|i: &f64| -> bool { .and(|i: &f64| -> bool {
implement_compare!(mtch, "header-float-neq", f64, |cmp| *i != cmp) implement_compare!(mtch, "header-float-neq", f64, |cmp: f64| (*i - cmp).abs() > EPS_CMP)
}) })
.and(|i: &f64| -> bool { .and(|i: &f64| -> bool {
implement_compare!(mtch, "header-float-lt", f64, |cmp| *i < cmp) implement_compare!(mtch, "header-float-lt", f64, |cmp| *i < cmp)