[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

# Technical Reference: Base Operating System and Extensions, Volume 1

## lgamma, lgammal, or gamma Subroutine

### Purpose

Computes the natural logarithm of the gamma function.

### Libraries

lgamma, lgammal, and gamma:
IEEE Math Library (libm.a)
or System V Math Library (libmsaa.a)

### Syntax

```#include <math.h>
```

```extern int signgam;
```

```double lgamma (x)
double x;
```

```long double lgammal (x)
long double x;
```

```double gamma (x)
double x;
```

### Description

The subroutine names lgamma and gamma are different names for the same function. The lgammal subroutine provides the same function for numbers in long double format.

The lgamma subroutine returns the natural logarithm of the absolute value of the gamma function of the x parameter.

```G(x) = integral [0 to INF] of ((e**(-t) * t**(x-1) dt)
```

The sign of lgamma of x is stored in the external integer variable signgam. The x parameter may not be a non-positive integer.

Do not use the expression:

```g = exp(lgamma(x)) * signgam
```

to compute g = G(x). Instead, use a sequence such as:

```lg = lgamma(x);
g = exp(lg) * signgam;
```

Note: Compile any routine that uses subroutines from the libm.a with the -lm flag. To compile the lgamma.c file, enter:

```cc lgamma.c -lm
```

### Parameters

 x For the lgamma and gamma subroutines, specifies a double-precision floating-point value. For the lgammal subroutine, specifies a long double-precision floating-point value.

### Error Codes

• For non-positive integer arguments, the lgamma and lgammal subroutines return NaNQ and set the division-by-zero bit in the floating-point exception status.
• If the correct value overflows, the lgamma and lgammal subroutines return a HUGE_VAL value. If the correct value underflows, the lgamma and lgammal subroutines return 0.

When using the libmsaa.a library with the -lmsaa flag:

• For non-positive integer arguments, the lgamma subroutine returns a HUGE_VAL value and set the errno global variable to a EDOM value. A message indicating SING error is printed on the standard error output.
• If the correct value overflows, the lgamma and lgammal subroutines and lgammal subroutine return a HUGE_VAL value and sets the errno global variable to a ERANGE value.

Note: These error-handling procedures may be changed with the matherr subroutine when using libmsaa.a (-lmsaa).

### Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

### Related Information

The exp, expm1, log, log10, log1p or pow (exp, expl, expm1, log, logl, log10, log10l, log1p, pow, or powl Subroutine) subroutine, matherr (matherr Subroutine) subroutine.

Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.

128-Bit long double Floating-Point Format in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]