diff options
author | flip1995 <hello@philkrones.com> | 2019-07-26 22:52:03 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-07-26 23:05:09 +0200 |
commit | 8469fd5596c4ab200b20342adefd7e0dad4d72f1 (patch) | |
tree | 7ff992f59458c00fa40514af932b5c96c7aadb4a /bin | |
parent | 2c26fd27531ec61299c7a4e15cee64c88316242e (diff) |
Fix float comparison bug found by clippy
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/core/imag-header/src/main.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/bin/core/imag-header/src/main.rs b/bin/core/imag-header/src/main.rs index 10c8805c..a7a5692d 100644 --- a/bin/core/imag-header/src/main.rs +++ b/bin/core/imag-header/src/main.rs @@ -66,6 +66,8 @@ use toml_query::read::TomlValueReadExt; mod ui; +const EPS_CMP: f64 = 1e-10; + fn main() { let version = make_imag_version!(); 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) .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 { - 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 { implement_compare!(mtch, "header-float-lt", f64, |cmp| *i < cmp) |