s Chapter Contents
s Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_complex_log_gamma (s14agc)

## 1  Purpose

nag_complex_log_gamma (s14agc) returns the value of the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ for complex $z$, .

## 2  Specification

 #include #include
 Complex nag_complex_log_gamma (Complex z, NagError *fail)

## 3  Description

nag_complex_log_gamma (s14agc) evaluates an approximation to the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ defined for $\mathrm{Re}\left(z\right)>0$ by
 $ln⁡Γz=ln⁡∫0∞e-ttz-1dt$
where $z=x+iy$ is complex. It is extended to the rest of the complex plane by analytic continuation unless $y=0$, in which case $z$ is real and each of the points $z=0,-1,-2,\dots \text{}$ is a singularity and a branch point.
nag_complex_log_gamma (s14agc) is based on the method proposed by Kölbig (1972) in which the value of $\mathrm{ln}\Gamma \left(z\right)$ is computed in the different regions of the $z$ plane by means of the formulae
 $ln⁡Γz = z-12ln⁡z-z+12ln⁡2π+z∑k=1K B2k2k2k-1 z-2k+RKz if ​x≥x0≥0, = ln⁡Γz+n-ln⁡∏ν=0 n-1z+ν if ​x0>x≥0, = ln⁡π-ln⁡Γ1-z-lnsin⁡πz if ​x<0,$
where $n=\left[{x}_{0}\right]-\left[x\right]$, $\left\{{B}_{2k}\right\}$ are Bernoulli numbers (see Abramowitz and Stegun (1972)) and $\left[x\right]$ is the largest integer $\text{}\le x$. Note that care is taken to ensure that the imaginary part is computed correctly, and not merely modulo $2\pi$.
The function uses the values $K=10$ and ${x}_{0}=7$. The remainder term ${R}_{K}\left(z\right)$ is discussed in Section 7.
To obtain the value of $\mathrm{ln}\Gamma \left(z\right)$ when $z$ is real and positive, nag_log_gamma (s14abc) can be used.

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Kölbig K S (1972) Programs for computing the logarithm of the gamma function, and the digamma function, for complex arguments Comp. Phys. Comm. 4 221–226

## 5  Arguments

1:    $\mathbf{z}$ComplexInput
On entry: the argument $z$ of the function.
Constraint: ${\mathbf{z}}\mathbf{.}\mathbf{re}$ must not be ‘too close’ (see Section 6) to a non-positive integer when ${\mathbf{z}}\mathbf{.}\mathbf{im}=0.0$.
2:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_TOO_CLOSE_INTEGER
On entry, ${\mathbf{z}}\mathbf{.}\mathbf{re}$ is ‘too close’ to a non-positive integer when ${\mathbf{z}}\mathbf{.}\mathbf{im}=0.0$: ${\mathbf{z}}\mathbf{.}\mathbf{re}=〈\mathit{\text{value}}〉$, $\mathrm{nint}\left({\mathbf{z}}\mathbf{.}\mathbf{re}\right)=〈\mathit{\text{value}}〉$.

## 7  Accuracy

The remainder term ${R}_{K}\left(z\right)$ satisfies the following error bound:
 $RKz ≤ B2K 2K-1 z1-2K ≤ B2K 2K-1 x1-2Kif ​x≥0.$
Thus $\left|{R}_{10}\left(7\right)\right|<2.5×{10}^{-15}$ and hence in theory the function is capable of achieving an accuracy of approximately $15$ significant digits.

## 8  Parallelism and Performance

nag_complex_log_gamma (s14agc) is not threaded in any implementation.

None.

## 10  Example

This example evaluates the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ at $z=-1.5+2.5i$, and prints the results.

### 10.1  Program Text

Program Text (s14agce.c)

### 10.2  Program Data

Program Data (s14agce.d)

### 10.3  Program Results

Program Results (s14agce.r)