Tolerance.compare

Tolerance.compare(a, b, rtol, atol)[source]

Compare two values.

Parameters:
afloat

The first value.

bfloat

The second value.

rtolfloat

The relative tolerance.

atolfloat

The absolute tolerance.

Returns:
bool

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

Notes

In this comparison, b is considered the “true value”. This means that the relative part of the tolerance is computed as a fraction of b.

Examples

>>> tol = Tolerance()
>>> tol.compare(1.0, 1.001, 0.001, 1e-06)
True
>>> tol.compare(1.0, 1.001, 0.0001, 1e-06)
False