Tolerance.is_close

Tolerance.is_close(a, b, rtol=None, atol=None)[source]

Check if two values are close enough to be considered equal.

Parameters:
afloat

The first value.

bfloat

The second value.

rtolfloat, optional

The relative tolerance. Default is None, in which case self.relative is used.

atolfloat, optional

The absolute tolerance. Default is None, in which case self.absolute is used.

Returns:
bool

True if the values are close enough to be considered equal. False otherwise.

Examples

>>> tol = Tolerance()
>>> tol.is_close(1.0, 1.0 + 1e-5)
False
>>> tol.is_close(1.0, 1.0 + 1e-6)
True
>>> tol.is_close(0.1, 0.1 + 1e-5)
False
>>> tol.is_close(0.1, 0.1 + 1e-6)
False
>>> tol.is_close(0.1, 0.1 + 1e-7)
True
>>> tol.is_close(0, 0 + 1e-5)
False
>>> tol.is_close(0, 0 + 1e-6)
False
>>> tol.is_close(0, 0 + 1e-7)
False
>>> tol.is_close(0, 0 + 1e-8)
False
>>> tol.is_close(0, 0 + 1e-9)
True