cc [flag ...] file ... -lm [library ...]#include <math.h>
double gamma(double x);
double lgamma(double x);
extern int signgam;
signgam- storage for sign of lgamma
gamma and lgamma return
ln (|(x)|)
where (x) is defined as
The sign of
(x)
is returned in the external integer signgam.
The argument
x
may not be a non-positive integer.
The following C program fragment might be used to calculate
:
if ((y = gamma(x)) > LN_MAXDOUBLE) error(); y = signgam * exp(y);
where LN_MAXDOUBLE is the least value that causes exp to return a range error, and is defined in the values.h header file.
If the correct value would overflow, gamma and lgamma return a value that will compare equal to +HUGE_VAL and set errno to ERANGE.
On systems that support IEEE NaN, if x is a quiet NaN, that value is returned. If x is a signaling NaN, a quiet NaN is returned and the invalid operation exception is raised. In either case, errno is set to EDOM.
If the program was compiled with the -Xt compilation mode, a value that will compare equal to HUGE is returned instead of HUGE_VAL. In addition, for non-positive integer arguments, a message indicating SING error is printed on the standard error output. These error handling procedures may be changed with the function matherr.