Search
View source code
Display the source code in std/math/operations.d from which this page was generated on github.
Report a bug
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

# Function `std.math.operations.approxEqual`

Computes whether a values is approximately equal to a reference value, admitting a maximum relative difference, and a maximum absolute difference.

``` bool approxEqual(T, U, V) (   T value,   U reference,   V maxRelDiff = 0.01,   V maxAbsDiff = 1e-05 ); ```

## Warning

This template is considered out-dated. It will be removed from Phobos in 2.106.0. Please use `isClose` instead. To achieve a similar behaviour to `approxEqual(a, b)` use `isClose(a, b, 1e-2, 1e-5)`. In case of comparing to 0.0, `isClose(a, b, 0.0, eps)` should be used, where `eps` represents the accepted deviation from 0.0."

## Parameters

NameDescription
value Value to compare.
reference Reference value.
maxRelDiff Maximum allowable difference relative to `reference`. Setting to 0.0 disables this check. Defaults to `1e-2`.
maxAbsDiff Maximum absolute difference. This is mainly usefull for comparing values to zero. Setting to 0.0 disables this check. Defaults to `1e-5`.

## Returns

`true` if `value` is approximately equal to `reference` under either criterium. It is sufficient, when `value ` satisfies one of the two criteria.

If one item is a range, and the other is a single value, then the result is the logical and-ing of calling `approxEqual` on each element of the ranged item against the single item. If both items are ranges, then `approxEqual` returns `true` if and only if the ranges have the same number of elements and if `approxEqual` evaluates to `true` for each pair of elements.

Use `feqrel` to get the number of equal bits in the mantissa.

## Authors

Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger