| Home | Libraries | People | FAQ | More

### Termination Condition Functors

    template <class T>
    struct eps_tolerance
    {
       eps_tolerance();
       eps_tolerance(int bits);
       bool operator()(const T& a, const T& b)const;
    };

`eps_tolerance` is the usual termination condition used with these root finding functions. Its `operator()` will return true when the relative distance between a and b is less than four times the machine epsilon for T, or 21-bits, whichever is the larger. In other words, you set bits to the number of bits of precision you want in the result. The minimal tolerance of four times the machine epsilon of type T is required to ensure that we get back a bracketing interval, since this must clearly be at greater than one epsilon in size. While in theory a maximum distance of twice machine epsilon is possible to achieve, in practice this results in a great deal of "thrashing" given that the function whose root is being found can only ever be accurate to 1 epsilon at best.

    struct equal_floor
    {
       equal_floor();
       template <class T> bool operator()(const T& a, const T& b)const;
    };

This termination condition is used when you want to find an integer result that is the floor of the true root. It will terminate as soon as both ends of the interval have the same floor.

    struct equal_ceil
    {
       equal_ceil();
       template <class T> bool operator()(const T& a, const T& b)const;
    };

This termination condition is used when you want to find an integer result that is the ceil of the true root. It will terminate as soon as both ends of the interval have the same ceil.

    struct equal_nearest_integer
    {
       equal_nearest_integer();
       template <class T> bool operator()(const T& a, const T& b)const;
    };

This termination condition is used when you want to find an integer result that is the closest to the true root. It will terminate as soon as both ends of the interval round to the same nearest integer.