Skip to main content

approx_equal

Function approx_equal 

Source
pub fn approx_equal(a: f64, b: f64) -> bool
Expand description

Checks whether two floating-point numbers agree to the default tolerances.

Use this for calculated results. Invariants such as reset values, bounds or period-one passthrough are exact and should be asserted with ==.

ยงExample

use nautilus_indicators::testing::approx_equal;

// At 1e6 the relative bound is 1e-3, which covers a gap of 1e-4.
assert!(approx_equal(1e6 + 1e-4, 1e6));
assert!(!approx_equal(1.0, 1.000_1));