...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

boost::math::fpc::close_at_tolerance — Predicate for comparing floating point numbers.

// In header: <boost/test/tools/floating_point_comparison.hpp> template<typename FPT> class close_at_tolerance { public: // types typedef bool result_type; // construct/copy/destruct template<typename ToleranceType> explicit close_at_tolerance(ToleranceType, fpc::strength = FPC_STRONG); // public member functions FPT fraction_tolerance() const; fpc::strength strength() const; FPT tested_rel_diff() const; bool operator()(FPT, FPT) const; };

This predicate is used to compare floating point numbers. In addition the comparison produces maximum related difference, which can be used to generate detailed error message The methods for comparing floating points are detailed in the documentation. The method is chosen by the boost::math::fpc::strength given at construction.

This predicate is not suitable for comparing to 0 or to infinity.

`close_at_tolerance`

public member functions-
FPT fraction_tolerance() const;

Returns the tolerance. -
fpc::strength strength() const;

Returns the comparison method. -
FPT tested_rel_diff() const;

Returns the failing fraction. -
bool operator()(FPT left, FPT right) const;

Compares two floating point numbers a and b such that their "left" relative difference |a-b|/a and/or "right" relative difference |a-b|/b does not exceed specified relative (fraction) tolerance.

What is reported by

`tested_rel_diff`

in case of failure depends on the comparison method:for

`FPC_STRONG:`

the max of the two fractionsfor

`FPC_WEAK:`

the min of the two fractions The rationale behind is to report the tolerance to set in order to make a test pass.

Parameters:

`left`

first floating point number to be compared

`right`

second floating point number to be compared