Function russell_lab::check::complex_approx_eq

source ·
pub fn complex_approx_eq<T>(a: Complex<T>, b: Complex<T>, tol: f64)
where T: Num + NumCast + Copy,
Expand description

Panics if two numbers are not approximately equal to each other

§Panics

  1. Will panic if NAN, INFINITY, or NEG_INFINITY is found
  2. Will panic if the absolute difference of each real/imag part is greater than the tolerance

§Input

a – Left value b – Right value tol: f64 – Error tolerance: panics occurs if |a.re - b.re| > tol or |a.im - b.im| > tol

§Examples

§Accepts small error

use russell_lab::*;

fn main() {
    let a = cpx!(3.0000001, 2.0000001);
    let b = cpx!(3.0, 2.0);
    complex_approx_eq(a, b, 1e-6);
}

§Panics on different values

§Real part

use russell_lab::*;

fn main() {
    let a = cpx!(1.0, 3.0);
    let b = cpx!(2.0, 3.0);
    complex_approx_eq(a, b, 1e-6);
}

§Imaginary part

use russell_lab::*;

fn main() {
    let a = cpx!(1.0, 3.0);
    let b = cpx!(1.0, 4.0);
    complex_approx_eq(a, b, 1e-6);
}