gamma_log_real returns the value of the logarithm of the gamma function, .

For full information please refer to the NAG Library document for s14ab


The argument of the function.


The value of .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and the constant .

Constraint: .


gamma_log_real calculates an approximate value for . It is based on rational Chebyshev expansions.

Denote by a ratio of polynomials of degree in the numerator and in the denominator. Then:

for ,

for ,

for ,

for ,

and for ,

For each expansion, the specific values of and are selected to be minimal such that the maximum relative error in the expansion is of the order , where is the maximum number of decimal digits that can be accurately represented for the particular implementation (see machine.decimal_digits).

Let denote machine precision and let denote the largest positive model number (see machine.real_largest). For the value is not defined; gamma_log_real returns zero and exits with = 1. It also exits with = 1 when , and in this case the value is returned. For in the interval , the function to machine accuracy.

Now denote by the largest allowable argument for on the machine. For the term in Equation (1) is negligible. For there is a danger of setting overflow, and so gamma_log_real exits with = 2 and returns .


NIST Digital Library of Mathematical Functions

Cody, W J and Hillstrom, K E, 1967, Chebyshev approximations for the natural logarithm of the gamma function, Math.Comp. (21), 198–203