lgamma(), gamma(), lgamma_r(), gamma_r() - log gamma function, gamma function, signgam variable
#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)
Gamma(x) returns |¯(x), with no effect on signgam.
Depending on the value of the variable _LIB_VERSION,
lgamma(3) may be the same as gamma(3) (as specified by
the XPG) or it may 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. See
NOTES.
The external integer signgam returns the sign of |¯(x).
The functions gamma_r(3) and lgamma_r(3) are reentrant versions of gamma(3) and lgamma(3) (where lgamma_r(3) always returns the logarithm of the gamma function). The argument signgamp is a pointer to a user-provided variable which will contain the sign of the x) after the call returns.
Do not use the expression signgam*exp(lgamma(x)) to compute g := |¯(x). Instead use a program like this (in C):
lg = lgamma(x); g = signgam*exp(lg);
Only after lgamma(3) has returned can signgam be correct.
For arguments in its range, gamma(3) is preferred, as for positive arguments it is accurate to within one unit in the last place. Exponentiation of lgamma(3) will lose up to 10 significant bits.
Gamma(3) and lgamma(3) return appropriate values unless an argument is out of range. Overflow will occur for sufficiently large positive values. For large non-integer negative values, gamma(3) will underflow.
The lgamma(3) function can fail for the following reasons:
The name gamma(3) was originally dedicated to the
lgamma(3) function, so some old code may no
longer be compatible. For this reason, the XPG specifications make
gamma(3) and lgamma(3) identical. If you want lgamma(3) to
actually return the logarithm, set the value of the global variable
_LIB_VERSION to the value _BSD44_
(the default
value is _XOPEN_
).
The variable _LIB_VERSION dictates the conformance
aspects of the math APIs, primarily errors and boundary conditions.
The code has only been tested for conformance with the value
_XOPEN_
.
To avoid possible conflicts in behavior, set _LIB_VERSION
to _BSD44_
immediately before the call to lgamma(3) and
set it back to _XOPEN_
immediately after.
math(3)