pub fn assert_float_eq( f1: T, f2: T, atol: T, rtol: T, msg: &str, ) { println!("tol {}", atol + rtol * f2.abs()); println!("d {}", (f1 - f2).abs()); if (f1 - f2).abs() >= atol + rtol * f2.abs() { println!("Floats not almost equal. {}\nf1: {}\nf2: {}\n", msg, f1, f2); assert!(false); } else if f1.is_nan() || f2.is_nan() { println!("NaN detected. {}\nf1: {}\nf2: {}\n", msg, f1, f2); assert!(false); } } #[cfg(test)] pub fn assert_float_eq_f64(f1: f64, f2: f64) { assert_float_eq(f1, f2, 1e-12, 0.0, ""); }