macro_rules! assert_complex_vec_approx_eq {
    ($a:expr, $b:expr, $tol:expr) => { ... };
}
Expand description

Asserts that two complex vectors have the same length and approximately equal values

Input

  • a – Left vector
  • b – Right vector
  • tol: f64 – Error tolerance such that |a[i].re - b[i].re| < tol and |a[i].im - b[i].im| < tol for all i in [0,a.len()]

Note

This macro also checks that a.len() == b.len()

Examples

Accepts small error

#[macro_use] extern crate russell_chk;

use num_complex::Complex64;

fn main() {
    let a = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0), Complex64::new(3.0000001, 6.0)];
    let b = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0), Complex64::new(3.0, 6.0)];
    assert_complex_vec_approx_eq!(a, b, 1e-6);
}

Panics on different values

#[macro_use] extern crate russell_chk;

use num_complex::Complex64;

fn main() {
    let a = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0), Complex64::new(3.0, 6.0)];
    let b = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0), Complex64::new(4.0, 6.0)];
    assert_complex_vec_approx_eq!(a, b, 1e-6);
}

Panics on different lengths

#[macro_use] extern crate russell_chk;

use num_complex::Complex64;

fn main() {
    let a = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0), Complex64::new(3.0, 6.0)];
    let b = [Complex64::new(1.0, 4.0), Complex64::new(2.0, 5.0)];
    assert_complex_vec_approx_eq!(a, b, 1e-6);
}