Skip to main content

lfa/
utils.rs

1#![allow(dead_code)]
2
3pub(crate) fn eq_with_nan_eq(a: f64, b: f64, tol: f64) -> bool {
4    (a.is_nan() && b.is_nan()) || (a - b).abs() < tol
5}
6
7pub(crate) fn compare_floats<T1, I1, T2, I2>(a: I1, b: I2, tol: f64) -> bool
8where
9    T1: std::borrow::Borrow<f64>,
10    I1: IntoIterator<Item = T1>,
11    T2: std::borrow::Borrow<f64>,
12    I2: IntoIterator<Item = T2>,
13{
14    a.into_iter()
15        .zip(b.into_iter())
16        .all(move |(x, y)| (x.borrow() - y.borrow()).abs() < tol)
17}