The OpenD Programming Language

shouldApprox

  1. ShouldApprox!T shouldApprox(T value, T maxRelDiff, T maxAbsDiff)
  2. ShouldApprox!(T, F) shouldApprox(T value, F maxRelDiff, F maxAbsDiff)
    shouldApprox
    (
    T
    F
    )
    (
    const T value
    ,
    const F maxRelDiff = double
    ,
    const F maxAbsDiff = double
    )
    if (
    __traits(hasMember, T, "approxEqual") &&
    __traits(isFloating, F)
    )

Examples

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);
1.0.shouldApprox == 1 + 9e-7;
shouldApprox(1 + 9e-7, 1e-6, 1e-6) == 1;

Meta