Function russell_lab::check::approx_eq

source ·
pub fn approx_eq<T>(a: T, b: 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 is greater than the tolerance

§Input

a – Left value b – Right value tol: f64 – Error tolerance: panic occurs if |a - b| > tol

§Examples

§Accepts small error

use russell_lab::approx_eq;

fn main() {
    let a = 3.0000001;
    let b = 3.0;
    approx_eq(a, b, 1e-6);
}

§Panics on different value

use russell_lab::approx_eq;

fn main() {
    let a = 1.0;
    let b = 2.0;
    approx_eq(a, b, 1e-6);
}