...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
Assertions in the Unit Test Framework use two kinds
of comparison. For
being close to zero with absolute tolerance
abs(u) <= eps; // (abs)
v being close with relative tolerance
abs(u - v)/abs(u) <= eps && abs(u - v)/abs(v) <= eps; // (rel)
For rationale for choosing these formulae, see section Floating point comparison algorithms.
BOOST_TEST (when comparing floating-point
numbers) uses the following algorithm:
vis zero, evaluates formula (abs) on the other value.
Therefore in order to check if a number is close to zero with tolerance, you need to type:
BOOST_TEST(v == T(0), tt::tolerance(eps));
The compatibility assertions
BOOST_<level>_CLOSE_FRACTION perform formula
The compatibility assertion
BOOST_<level>_SMALL performs formula (abs).
The Unit Test Framework also provides unary predicate
binary predicate predicate
implement formula (abs) and (rel) respectively.
Tolerance-based computations also apply to
operator< and other relational operators. The
semantics are defined as follows:
This implies that the exactly one of these:
Relation less-at-tolerance is not a Strict
Weak Ordering as it lacks the transitivity of
the equivalence; using it as predicate in