Calculates the natural logarithm of the Gamma function with argument \e x.

View versions (1)

Interface

#include <codecogs/maths/special/gamma/log_gamma.h>

using namespace Maths::Special::Gamma;

This algorithm uses rational functions that approximate \log \Gamma(x) to at least 18 significant decimal digits. The accuracy achieved also depends on the arithmetic system and the compiler.

Example:

#include <codecogs/maths/special/gamma/log_gamma.h>
#include <iostream>
#include <iomanip>
int main()
{
  for (double x = 0; x <= 10; x += 0.5)
  {
    std::cout << "log Gamma(" << x << ") = " << std::setprecision(20);
    std::cout << Maths::Special::Gamma::log_gamma(x) << std::endl;
  }
  return 0;
}

Output:

log Gamma(0) = 1.#INF
log Gamma(0.5) = 0.57236494292469997
log Gamma(1) = 0
log Gamma(1.5) = -0.12078223763524526
log Gamma(2) = 0
log Gamma(2.5) = 0.28468287047291918
log Gamma(3) = 0.6931471805599454
log Gamma(3.5) = 1.2009736023470743
log Gamma(4) = 1.7917594692280552
log Gamma(4.5) = 2.4537365708424423
log Gamma(5) = 3.1780538303479453
log Gamma(5.5) = 3.9578139676187161
log Gamma(6) = 4.7874917427820449
log Gamma(6.5) = 5.6625620598571409
log Gamma(7) = 6.5792512120101012
log Gamma(7.5) = 7.5343642367587336
log Gamma(8) = 8.5251613610654129
log Gamma(8.5) = 9.5492672573009987
log Gamma(9) = 10.604602902745247
log Gamma(9.5) = 11.689333420797267
log Gamma(10) = 12.801827480081469

References

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

x
the desired argument

Returns

the natural logarithm of \Gamma(x)
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

x
Result