The OpenD Programming Language

ShouldApprox

struct ShouldApprox (
T
F = T
) if (
(
__traits(isFloating, T) ||
__traits(hasMember, T, "approxEqual")
)
&&
__traits(isFloating, F)
) {}

Members

Functions

opEquals
void opEquals(T expected, string file, int line)

Variables

maxAbsDiff
F maxAbsDiff;
maxRelDiff
F maxRelDiff;
value
T value;

Examples

1.0.shouldApprox == 1 + 9e-7;
shouldApprox(1 + 9e-7, 1e-6, 1e-6) == 1;
static struct C {
    double re, im;
    auto approxEqual(C rhs, double maxRelDiff, double maxAbsDiff)
    {
        import mir.math.common: approxEqual;
        return approxEqual(re, rhs.re, maxRelDiff, maxAbsDiff) && approxEqual(im, rhs.im, maxRelDiff, maxAbsDiff);
    }
}
C(1.0, 1.0).shouldApprox == C(1 + 9e-7, 1 - 9e-7);

Meta