cc [ flag ... ] file ... -lm [ library ... ] #include <math.h> extern int signgam;double lgamma(double x);
The lgamma(), gamma(), lgamma_r(), and gamma_r() functions return
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.
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.
For exceptional cases, matherr(3M) tabulates the values to be returned as dictated by various Standards.
See attributes(5) for descriptions of the following attributes:
See NOTES below.
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.