Synopsis
#include <boost/math/special_functions/gamma.hpp>
namespace boost{ namespace math{ template <class T> calculated-result-type tgamma(T z); template <class T, class Policy> calculated-result-type tgamma(T z, const Policy&); template <class T> calculated-result-type tgamma1pm1(T dz); template <class T, class Policy> calculated-result-type tgamma1pm1(T dz, const Policy&); }} // namespaces Descriptiontemplate <class T> calculated-result-type tgamma(T z); template <class T, class Policy> calculated-result-type tgamma(T z, const Policy&); Returns the "true gamma" (hence name tgamma) of value z:
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
There are effectively two versions of the tgamma function internally: a fully generic version that is slow, but reasonably accurate, and a much more efficient approximation that is used where the number of digits in the significand of T correspond to a certain Lanczos approximation. In practice any built in floating point type you will encounter has an appropriate Lanczos approximation defined for it. It is also possible, given enough machine time, to generate further Lanczos approximation's using the program libs/math/tools/lanczos_generator.cpp.
The return type of this function is computed using the result
type calculation rules: the result is template <class T> calculated-result-type tgamma1pm1(T dz); template <class T, class Policy> calculated-result-type tgamma1pm1(T dz, const Policy&);
Returns
The return type of this function is computed using the result
type calculation rules: the result is
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
AccuracyThe following table shows the peak errors (in units of epsilon) found on various platforms with various floating point types, along with comparisons to the GSL-1.9, GNU C Lib, HP-UX C Library and Cephes libraries. Unless otherwise specified any floating point type that is narrower than the one shown will have effectively zero error.
TestingThe gamma is relatively easy to test: factorials and half-integer factorials can be calculated exactly by other means and compared with the gamma function. In addition, some accuracy tests in known tricky areas were computed at high precision using the generic version of this function.
The function Implementation
The generic version of the
where l is an arbitrary integration limit: choosing
For types of known precision the Lanczos
approximation is used, a traits class For z in the range -20 < z < 1 then recursion is used to shift to z > 1 via:
For very small z, this helps to preserve the identity:
For z < -20 the reflection formula:
is used. Particular care has to be taken to evaluate the Finally if the argument is a small integer then table lookup of the factorial is used.
The function |