# `pymor.tools.floatcmp`¶

## Module Contents¶

### Functions¶

 `float_cmp` Compare x and y component-wise for almost equality. `float_cmp_all` Compare x and y for almost equality. `bounded` Check if x is strictly in bounds (lower, upper) or float_compares equal to lower or upper. `almost_less` Component-wise check if x <= y up to a given tolerance.
pymor.tools.floatcmp.float_cmp(x, y, rtol=1e-14, atol=1e-14)[source]

Compare x and y component-wise for almost equality.

For scalars we define almost equality as

```float_cmp(x,y) <=> |x - y| <= atol + |y|*rtol
```

Note

Numpy’s `allclose` method uses the same definition but treats arrays containing infinities as close if the infinities are at the same places and all other entries are close. In our definition, arrays containing infinities can never be close which seems more appropriate in most cases.

Parameters

x, y

`NumPy arrays` to be compared. Have to be broadcastable to the same shape.

rtol

The relative tolerance.

atol

The absolute tolerance.

pymor.tools.floatcmp.float_cmp_all(x, y, rtol=None, atol=None)[source]

Compare x and y for almost equality.

Returns `True` if all components of `x` are almost equal to the corresponding components of `y`.

pymor.tools.floatcmp.bounded(lower, upper, x, rtol=None, atol=None)[source]

Check if x is strictly in bounds (lower, upper) or float_compares equal to lower or upper.

Parameters

lower

Lower bound

upper

Upper bound

x

value to check

rtol

relative tolerance for float_cmp

atol

absolute tolerance for float_cmp

pymor.tools.floatcmp.almost_less(x, y, rtol=1e-14, atol=1e-14)[source]

Component-wise check if x <= y up to a given tolerance.

For scalars the check is given by

```almost_less(x, y) <=> (x - y  <= atol + |y| * rtol)
```

Parameters

x, y

`NumPy arrays` to be compared. Have to be broadcastable to the same shape.

rtol

The relative tolerance.

atol

The absolute tolerance.