Skip to main content

approx_equal

Function approx_equal 

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

Checks for approximate equality between two f64 values within a defined tolerance.

This function compares two floating-point numbers and returns true if the absolute difference between them is less than the predefined TOLERANCE constant. It is useful for comparing floating-point values that may be subject to small rounding errors.

§Arguments

  • a - The first f64 value to compare.
  • b - The second f64 value to compare.

§Returns

true if the absolute difference between a and b is less than TOLERANCE, false otherwise.

§Example

use optionstratlib_core::utils::numeric::approx_equal;

let x = 1.0;
let y = 1.00000001;
assert!(approx_equal(x, y)); // Returns true

let x = 1.0;
let y = 1.1;
assert!(!approx_equal(x, y)); // Returns false