Skip to content

Commit

Permalink
Use new stable total_cmp function to compare floats
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 authored and marco-c committed Jul 11, 2022
1 parent 5c0da1d commit 09ef915
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 09ef915

Please sign in to comment.