◆ gammaln()

IEEEValue boost::simd::gammaln ( IEEEValue const &  x)

This function object computes the natural logarithm of the absolute value of the Gamma function: \(\displaystyle \log |\Gamma(x)|\).

Header <boost/simd/function/gammaln.hpp>
Notes
  • The accuracy of the function is not uniformly good for negative entries The algorithm used is currently an adapted vesion of the cephes one. For better accuracy in the negative entry case, one can use the extern boost_math gammaln function but at a loss of speed.

    However, as stated in boost math:

    "While the relative errors near the positive roots of lgamma are very low, the function has an infinite number of irrational roots for negative arguments: very close to these negative roots only a low absolute error can be guaranteed."

  • The call gammaln(x, sgn) also returns the sign of gamma in the output parameter sgn.

    Be aware that POSIX version of lgamma is not thread-safe: each execution of the function stores the sign of the gamma function of x in the static external variable signgam.

    boost.simd also provides signgam which independantly computes the sign.

Decorators
  • std_ fcalls std::lgamma
See also
gamma, signgam
Example:
#include <boost/simd/eulerian.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main() {
pack_ft pf = {1.0f, 2.0f, -1.5f, 0.5f};
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::gammaln(pf) = " << bs::gammaln(pf) << '\n';
float xf = 2.0f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::gammaln(xf) = " << bs::gammaln(xf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1.5, 0.5)
-> bs::gammaln(pf) = (-0, 0, 0.860047, 0.572365)
---- scalar
<- xf = 2
-> bs::gammaln(xf) = 0