## lgamma(3M)

NAME
| SYNOPSIS
| DESCRIPTION
| IDIOSYNCRASIES
| RETURN VALUES
| ATTRIBUTES
| SEE ALSO
| NOTES

#### NAME

lgamma, lgamma_r, gamma, gamma_r– log
gamma function

#### SYNOPSIS

cc [ `flag` ... ] `file` ... **-lm** [ `library` ... ]
#include <math.h>
extern int signgam;

double lgamma(double

`x`);

double gamma(double

`x`);

double lgamma_r(double

`x`, int *

`signgamp`);

double gamma_r(double

`x`, int *

`signgamp`);

#### DESCRIPTION

The **lgamma()**, **gamma()**, **lgamma_r()**, and **gamma_r()** functions return

where

for x > 0 and

for x < 1.

The **lgamma()** and **gamma()** functions use the external integer `signgam` to return the sign of `|~(x)` while **lgamma_r()** and **gamma_r()** use the user-allocated space addressed by `signgamp`.

#### IDIOSYNCRASIES

In the case of **lgamma()**, do **not** use the expression `signgam*exp(lgamma(x))` to compute

Instead compute **lgamma()** first:

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

only after **lgamma()** has returned can `signgam` be correct. Note that `|~(x)` must overflow when `x` is large enough, underflow when **-x** is large enough, and generate a division by 0 exception at the singularities `x` a nonpositive integer.

#### RETURN VALUES

For exceptional cases, matherr(3M) tabulates the values to be returned as dictated by various Standards.

#### ATTRIBUTES

#### SEE ALSO

#### NOTES

Although **lgamma_r()** is not mentioned by POSIX 1003.1c, it was added to complete the functionality provided by similar thread-safe functions.

The **gamma()** function is currently maintained for compatibility with SVID3. See standards(5). The **gamma()** function and
the **gamma_r()** function may be removed from a future release. The **lgamma()** and **lgamma_r()** functions should be used instead.

When compiling multi-thread applications, the `_REENTRANT` flag must be defined on the compile line. This flag should only be used in multi-thread applications.

The **lgamma()** function is unsafe in multithreaded applications. The **lgamma_r()** function should be used instead.

SunOS 5.9 Last Revised 12 Jul 2002

NAME
| SYNOPSIS
| DESCRIPTION
| IDIOSYNCRASIES
| RETURN VALUES
| ATTRIBUTES
| SEE ALSO
| NOTES