nearly

Macro nearly 

Source
nearly!() { /* proc-macro */ }
Expand description

Returns whether the given comparison is nearly true using the provided tolerance.

The comparison can be:

  • a == b for testing whether a is nearly equal to b
  • a != b for testing whether a is not nearly equal to b

The tolerance used can be:

  • eps for an absolute epsilon tolerance
  • ulps for an ulps based tolerance
  • tol for an absolute epsilon and ulps based tolerance
  • default for an absolute epsilon and ulps based tolerance using default values

ยงExamples

use nearly::{nearly, Tolerance};

let a: f32 = 1.0;
let b: f32 = 1.0;

// use absolute epsilon tolerance
let eq: bool = nearly!(a == b, eps = 0.01);

// use ulps based tolerance
let eq: bool = nearly!(a == b, ulps = 5);

// use absolute epsilon and ulps based tolerance
let eq: bool = nearly!(a == b, eps = 0.01, ulps = 5);
let eq: bool = nearly!(a == b, tol = Tolerance::new(0.01, 5));

// use default absolute epsilon and default ulps based tolerance
let eq: bool = nearly!(a == b);