The OpenD Programming Language

shouldApprox

  1. ShouldApprox!T shouldApprox(T value, T maxRelDiff, T maxAbsDiff)
    shouldApprox
    (
    T
    )
    (
    const T value
    ,
    const T maxRelDiff = T(0x1p-20f)
    ,
    const T maxAbsDiff = T(0x1p-20f)
    )
    if (
    __traits(isFloating, T)
    )
  2. ShouldApprox!(T, F) shouldApprox(T value, F maxRelDiff, F maxAbsDiff)

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