From 09ef915b40f9be3b9f8d48178c52455c9b93fcdf Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 1 Jul 2022 13:52:21 +0200 Subject: [PATCH] Use new stable total_cmp function to compare floats --- src/macros.rs | 5 ++--- tests/test.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index f12e517a8..404d5baad 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -318,9 +318,8 @@ macro_rules! check_metrics { $( $( - let value: f64 = $true_float_value; - if !value.is_nan() { - assert!((func_space.metrics.$metric.$func_float() - value).abs() < f64::EPSILON); + if !($true_float_value as f64).is_nan() { + assert!(func_space.metrics.$metric.$func_float().total_cmp(&$true_float_value) == std::cmp::Ordering::Equal); } else { assert!(func_space.metrics.$metric.$func_float().is_nan()); } diff --git a/tests/test.rs b/tests/test.rs index b8c0a09a2..3694d849d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -178,7 +178,7 @@ fn compare_f64(f1: f64, f2: &serde_json::Value) { } else { let ft1 = f64::trunc(f1 * 1000.0) / 1000.0; let ft2 = f64::trunc(f2.as_f64().unwrap() * 1000.0) / 1000.0; - assert!((ft1 - ft2).abs() < f64::EPSILON); + assert!(ft1.total_cmp(&ft2) == std::cmp::Ordering::Equal); } }