Assertion.approxEqual

Asserts that a float type is aproximated equal. Returns the valued wrapped around the assertion

struct Assertion(T)
@trusted
T
approxEqual
(
U = double
)
(,
U maxRelDiff = CommonDefaultFor!(T, U)
,
U maxAbsDiff = 0.0
,
string file = __FILE__
,
size_t line = __LINE__
)
if (
is(T : real) &&
__traits(isFloating, T)
&&
is(U : real)
&&
__traits(isFloating, U)
)

Parameters

other U

Value to compare to compare.

maxRelDiff U

Maximum allowable relative difference. Setting to 0.0 disables this check. Default depends on the type of other and the original valie: It is approximately half the number of decimal digits of precision of the smaller type.

maxAbsDiff U

Maximum absolute difference. This is mainly usefull for comparing values to zero. Setting to 0.0 disables this check. Defaults to 0.0.

file string

filename

line size_t

line number inside of file

Examples

double d = 0.1;
double d2 = d + 1e-10;
d.should.not.be.equal(d2);
d.should.be.approxEqual(d2);

Meta