2020-12-18 22:46:21 +08:00
|
|
|
#![allow(dead_code)]
|
2020-11-29 08:41:16 +08:00
|
|
|
use super::Complex;
|
|
|
|
|
2020-12-17 08:02:17 +08:00
|
|
|
pub fn isclose(a: f64, b: f64, rtol: f64, atol: f64) -> bool {
|
|
|
|
(a - b).abs() <= a.abs().max(b.abs()) * rtol + atol
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn isclosef(a: f32, b: f32, rtol: f32, atol: f32) -> bool {
|
2020-12-05 01:09:23 +08:00
|
|
|
(a - b).abs() <= a.abs().max(b.abs()) * rtol + atol
|
2020-11-29 08:41:16 +08:00
|
|
|
}
|
|
|
|
|
2020-12-05 01:09:23 +08:00
|
|
|
pub fn complex_isclose(
|
2020-11-29 08:41:16 +08:00
|
|
|
a: Complex<f32>,
|
|
|
|
b: Complex<f32>,
|
2020-12-05 01:09:23 +08:00
|
|
|
rtol: f32,
|
|
|
|
atol: f32,
|
2020-11-29 08:41:16 +08:00
|
|
|
) -> bool {
|
2020-12-17 08:02:17 +08:00
|
|
|
isclosef(a.0, b.0, rtol, atol) && isclosef(a.1, b.1, rtol, atol)
|
2020-11-29 08:41:16 +08:00
|
|
|
}
|
|
|
|
|
2020-12-05 01:09:23 +08:00
|
|
|
pub fn complex_allclose(
|
2020-11-29 08:41:16 +08:00
|
|
|
a: &[Complex<f32>],
|
|
|
|
b: &[Complex<f32>],
|
2020-12-05 01:09:23 +08:00
|
|
|
rtol: f32,
|
|
|
|
atol: f32,
|
2020-11-29 08:41:16 +08:00
|
|
|
) -> bool {
|
2020-12-18 22:46:21 +08:00
|
|
|
a.iter()
|
|
|
|
.zip(b)
|
|
|
|
.all(|(&i, &j)| complex_isclose(i, j, rtol, atol))
|
2020-11-29 08:41:16 +08:00
|
|
|
}
|