is_almost_equal#

caf.toolkit.math_utils.is_almost_equal(val1, val2, rel_tol=0.0001, abs_tol=0.0)[source]#

Check if two values are similar.

Whether two values are considered close is determined according to given absolute and relative tolerances. Wrapper around ` math.isclose()` to set default values for rel_tol and abs_tol.

Parameters:
  • val1 (int | float) – The first value to check if close to val2

  • val2 (int | float) – The second value to check if close to val1

  • rel_tol (float) – The relative tolerance – it is the maximum allowed difference between val1 and val2, relative to the larger absolute value of val1 or val2. By default, this is set to 0.0001, meaning the values must be within 0.01% of each other.

  • abs_tol (float) – The minimum absolute tolerance – useful for comparisons near zero. Must be at least zero.

Returns:

True if val1 and val2 are similar. False otherwise.

Return type:

is_close

See also

math.isclose()