gamma(3M)
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
ln||~(x)|
where
|~(x) = integral from 0 to +Infinity of pow(t,x-1)*exp(-t)
dt
for x > 0 and
|~(x) = n/(|~(1-x)sin(nx))
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
`g := |~(x)'
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, under-
flow 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 attributes(5) for descriptions of the following attri-
butes:
____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| MT-Level | See NOTES below. |
|_____________________________|_____________________________|
SEE ALSO
matherr(3M), attributes(5), standards(5)
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 compatibil-
ity 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 applica-
tions. The lgamma_r() function should be used instead.
Man(1) output converted with
man2html