# GAMMALN

## Purpose:

Computes the natural log of the gamma
function. GAMMALN is often used in place of GAMMA when the value of GAMMA
becomes very large.

## Syntax:

GAMMALN(z)

z |
- |
A scalar, series or table, the exponential
factor. |

## Returns:

A scalar, series, or table.

## Example:

gammln({1,2,3})

returns a series {-3.4136E-011,-7.8188E-011,6.9315E-001},
the natural log of GAMMA.

## Example:

a = gammaln(1+i);

b = ln(gamma(1+i));

a == b == -0.650923 - 0.301640i

## Remarks:

The gamma function **Γ**(*z*),
is defined as:

The gamma function for integer *n* is the factorial of *n *-
1 such that:

gamma(n) == prod(1..n-1)

The gamma function extends the factorial
function for real and complex values and can be considered an interpolating
function for the integer factorial function.

GAMMALN computes the natural log of the
GAMMA function:

For **z**
< 0, GAMMALN uses a 15 term Lanczos approximation developed by Paul
Godfrey to achieve 15 digit accuracy for real inputs and 13 digit accuracy
for complex inputs. For other values of **z**,
an algorithm due to Didonato and Morris is employed [1].

In practice, it is often advisable to
recast equations to use GAMMALN instead of GAMMA,
as the GAMMA value of arguments greater than 171.62 exceeds the maximum
floating point representation.

## See Also:

FACTORIAL

GAMM

GAMMA

GAMMAINC

GAMMAP

GAMMAQ

## References:

[1] Didonato
and Morris

* Algorithm
708: Significant Digit Computation of the Incomplete Beta Function Ratios*

TOMS
1992, 18(3), 360-373