The LNGAMMA function accepts a positive real number and returns the natural logarithm of the GAMMA function at that number. The algorithm used varies depending on the value of argument x.
If x is less than 3.28, the following algorithm is used:
LNGAMMA(x) = LN(GAMMA(x))
If x is greater than or equal to 3.28, the calculation is more direct, relying on Stirling's approximation as follows:
GAMMA(x) = (e**(-x)*x**(x-1/2)*SQRT(2*pi))g(x)
In the preceding calculation, the function g(x) is an error polynomial.