# NAG FL Interfaces14agf (gamma_​log_​complex)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Function s14agf ( z,
 Complex (Kind=nag_wp) :: s14agf Integer, Intent (Inout) :: ifail Complex (Kind=nag_wp), Intent (In) :: z
#include <nag.h>
 Complex s14agf_ (const Complex *z, Integer *ifail)
The routine may be called by the names s14agf or nagf_specfun_gamma_log_complex.

## 3Description

s14agf 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.
s14agf 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-12)ln⁡z-z+12ln⁡2π+z∑k=1K B2k2k(2k-1) z-2k+RK(z) if ​x≥x0≥0, = ln⁡Γ(z+n)-ln⁡∏ν=0 n-1(z+ν) if ​x0>x≥0, = ln⁡π-ln⁡Γ(1-z)-ln(sin⁡π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 routine 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, s14abf can be used.
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

## 5Arguments

1: $\mathbf{z}$Complex (Kind=nag_wp) Input
On entry: the argument $z$ of the function.
Constraint: $\mathrm{Re}\left({\mathbf{z}}\right)$ must not be ‘too close’ (see Section 6) to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$.
2: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, $\mathrm{Re}\left({\mathbf{z}}\right)$ is ‘too close’ to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$. That is, .
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

s14agf is not threaded in any implementation.

None.

## 10Example

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.1Program Text

Program Text (s14agfe.f90)

### 10.2Program Data

Program Data (s14agfe.d)

### 10.3Program Results

Program Results (s14agfe.r)