approxEqual

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

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."

deprecated
bool
approxEqual
(
T
U
V
)
(,,
V maxRelDiff = 1e-2
,
V maxAbsDiff = 1e-5
)

Parameters

value T

Value to compare.

reference U

Reference value.

maxRelDiff V

Maximum allowable difference relative to reference. Setting to 0.0 disables this check. Defaults to 1e-2.

maxAbsDiff V

Maximum absolute difference. This is mainly usefull for comparing values to zero. Setting to 0.0 disables this check. Defaults to 1e-5.

Return Value

Type: bool

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.

See Also

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

Meta