Class funct_multip_tl (o2scl)

O2scl : Class List

template<class fp_25_t, class fp_35_t, class fp_50_t, class fp_100_t>
class funct_multip_tl

Use multiprecision to automatically evaluate a function to a specified level of precision.

The function must be specified as a template, i.e. it must be of the form template<class fp_t> fp_t function(fp_t x).

By default, this class uses a relative tolerance equal to \( 10^{-d+1} \), where \( d \) is the value returned by numeric_limits<fp_t>::digits10. This choice ensures that most exact or nearly exact functions will require only two function evaluations, one at double and one at long double precision. However, only simple functions can be evaluated to within this accuracy without more precise inputs. Preferably, the user should choose this tolerance carefully. If the tolerance is sufficiently small, no low-precision function evaluations will be performed.

This class will fail to evalate a function with the requested precision if:

  • the user-specified input and result data type does not have enough precision to compute or store the result (i.e. the tolerance is less than \( 10^{-m} \) where \( m \) is the value, returned by numeric_limits<fp_t>::max_digits10).

  • the requested precision is near to or smaller than 1.0e-50, or

  • the function is noisy, non-deterministic, or is discontinuous in the local neighborhood.

If verbose is 0, no output will be generated. If it is 1, then the tolerance and result will be output. If it is 2, then more diagnostics will be output.

Note

Experimental.

Note

The algorithm attempts not to be wasteful, but is not necessarily optimized for speed. One way to improve it would be to more intelligently choose the number of digits used in the boost multiprecision numbers based on the tolerance which was specified. Another way to improve this class would be to use other multiprecision types beyond boost.

Public Functions

inline funct_multip_tl()
inline ~funct_multip_tl()
template<typename func_t, class fp_t>
inline int eval_tol_err(func_t &&f, const fp_t &x, fp_t &val, fp_t &err, double tol_loc = -1) const

Evaluate the function and return the error estimate with the specified tolerance.

If tol_loc is positive and non-zero, then this is the relative tolerance used. If tol_loc is zero or negative and tol_rel is positive and non-zero, then tol_rel is used for the relative tolerance. Otherwise, if both of these values is negative, then the default relative tolerance is used.

template<typename func_t, class fp_t>
inline int eval_err(func_t &&f, const fp_t &x, fp_t &val, fp_t &err) const

Evaluate the function and return the error estimate with the default tolerance for the specified type.

template<typename func_t, class fp_t>
inline fp_t operator()(func_t &&f, const fp_t &x) const

Evalulate the function without an error estimate.

Public Members

int verbose

Verbosity parameter.

double tol_rel

Relative tolerance.

bool err_nonconv

If true, call the error handler if the function evaluation fails.