The OpenD Programming Language

approxEqual

Computes whether two values are approximately equal, admitting a maximum relative difference, and a maximum absolute difference.

bool
approxEqual
(
T
)
(
Complex!T lhs
,
Complex!T rhs
,
const T maxRelDiff = 0x1p-20f
,
const T maxAbsDiff = 0x1p-20f
)

Parameters

lhs Complex!T

First item to compare.

rhs Complex!T

Second item to compare.

maxRelDiff T

Maximum allowable difference relative to rhs. Defaults to 0.5 ^^ 20.

maxAbsDiff T

Maximum absolute difference. Defaults to 0.5 ^^ 20.

Return Value

Type: bool

true if the two items are equal or approximately equal under either criterium.

Examples

Complex types works as approxEqual(l.re, r.re) && approxEqual(l.im, r.im)

assert(approxEqual(complex(1.0, 1), complex(1.0000001, 1), 1.0000001));
assert(!approxEqual(complex(100000.0, 0), complex(100001.0, 0)));

Meta