approxEqual

testing function for float-point slices

pure nothrow @nogc
bool
approxEqual
(
L
R
V
)
(
L lhs
,
R rhs
,
V maxRelDiff = 1e-2
,
V maxAbsDiff = 1e-5
)
if (
isSlice!L &&
isSlice!R
)

Examples

import mir.ndslice : sliced;
static immutable eps = 1e-6;
static immutable _a = [1.0, 0.0,
                       0.0, 1.0];
auto a = _a.sliced(2, 2);
static immutable _b = [1.0, eps,
                       -eps, 1.0];
auto b = _b.sliced(2, 2);
assert(approxEqual(a, b, eps*2, eps*2));
assert(!approxEqual(a, b, eps/2, eps/2));

Meta