For the definition of the Gamma function, see tgamma(3).
The lgamma() function returns the natural logarithm of the absolute value
of the Gamma function. The sign of the Gamma function is returned in the
external integer signgam declared in <math.h>. It is 1
when the Gamma function is positive or zero, -1 when it is negative.
Since using a constant location signgam is not thread-safe, the functions
lgamma_r() etc. have been introduced; they return this sign via the
For nonpositive integer values of x, lgamma() returns HUGE_VAL,
sets errno to ERANGE and raises the zero divide exception. (Similarly,
lgammaf() returns HUGE_VALF and lgammal() returns HUGE_VALL.)
In order to check for errors, set errno to zero and call
feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return,
if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO |
FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred.
A range error occurs if x is too large. A pole error occurs if x is a negative
integer or zero.