exmex/util.rs
1#[cfg(test)]
2pub fn assert_float_eq<T: num_traits::Float + std::fmt::Display>(
3 f1: T,
4 f2: T,
5 atol: T,
6 rtol: T,
7 msg: &str,
8) {
9 println!("tol {}", atol + rtol * f2.abs());
10 println!("d {}", (f1 - f2).abs());
11 if (f1 - f2).abs() >= atol + rtol * f2.abs() {
12 println!("Floats not almost equal. {}\nf1: {}\nf2: {}\n", msg, f1, f2);
13 unreachable!();
14 }
15}
16
17#[cfg(test)]
18pub fn assert_float_eq_f64(f1: f64, f2: f64) {
19 assert_float_eq(f1, f2, 1e-12, 0.0, "");
20}