Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class template close_at_tolerance

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

Synopsis

// 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;
};

Description

This predicate is used to compare floating point numbers. In addition the comparison produces maximum related differnce, 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.

close_at_tolerance public construct/copy/destruct

  1. template<typename ToleranceType> 
      explicit close_at_tolerance(ToleranceType tolerance, 
                                  fpc::strength fpc_strength = FPC_STRONG);

close_at_tolerance public member functions

  1. FPT fraction_tolerance() const;
    Returns the tolerance.
  2. fpc::strength strength() const;
    Returns the comparison method.
  3. FPT tested_rel_diff() const;
    Returns the failing fraction.
  4. 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 fractions

    • for 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


PrevUpHomeNext