In module Test§

See primary documentation in context for sub is-approx.

multi is-approx(Numeric $got, Numeric $expected, $desc = '')
multi is-approx(Numeric $got, Numeric $expected, Numeric $abs-tol,
                    $desc = '')
multi is-approx(Numeric $got, Numeric $expected, $desc = '',
                    Numeric :$rel-tol is required)
multi is-approx(Numeric $got, Numeric $expected, $desc = '',
                    Numeric :$abs-tol is required)
multi is-approx(Numeric $got, Numeric $expected, $desc = '',
                    Numeric :$rel-tol is required,
                    Numeric :$abs-tol is required)

Marks a test as passed if the $got and $expected numerical values are approximately equal to each other. The subroutine can be called in numerous ways that let you test using relative tolerance ($rel-tol) or absolute tolerance ($abs-tol) of different values.

If no tolerance is set, the function will base the tolerance on the absolute value of $expected: if it's smaller than 1e-6, use absolute tolerance of 1e-5; if it's larger, use relative tolerance of 1e-6.

my Numeric ($value, $expected, $abs-tol, $rel-tol) = ...

is-approx $value, $expected;
is-approx $value, $expected, 'test description';

is-approx $value, $expected, $abs-tol;
is-approx $value, $expected, $abs-tol, 'test description';

is-approx $value, $expected, :$rel-tol;
is-approx $value, $expected, :$rel-tol, 'test description';

is-approx $value, $expected, :$abs-tol;
is-approx $value, $expected, :$abs-tol, 'test description';

is-approx $value, $expected, :$abs-tol, :$rel-tol;
is-approx $value, $expected, :$abs-tol, :$rel-tol, 'test description';