dsp: add f64 isclose testing function

This commit is contained in:
Matt Huszagh 2020-12-16 16:02:17 -08:00
parent 17f9f0750e
commit 6d651da758
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,10 @@
use super::Complex; use super::Complex;
pub fn isclose(a: f32, b: f32, rtol: f32, atol: f32) -> bool { 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 {
(a - b).abs() <= a.abs().max(b.abs()) * rtol + atol (a - b).abs() <= a.abs().max(b.abs()) * rtol + atol
} }
@ -10,7 +14,7 @@ pub fn complex_isclose(
rtol: f32, rtol: f32,
atol: f32, atol: f32,
) -> bool { ) -> bool {
isclose(a.0, b.0, rtol, atol) && isclose(a.1, b.1, rtol, atol) isclosef(a.0, b.0, rtol, atol) && isclosef(a.1, b.1, rtol, atol)
} }
pub fn complex_allclose( pub fn complex_allclose(