gamma(3M) SDK R4.11 gamma(3M)
NAME
gamma, lgamma - log gamma function
SYNOPSIS
cc [flag ...] file ... -lm [library ...]
#include <math.h>
double gamma (double x);
double lgamma (double x);
extern int signgam;
DESCRIPTION
gamma and lgamma return
ln(||¯(x)|)
where |¯(x) is defined as
integral from 0 to oo of e^(-t)t^(x-1)dt
The sign of |¯(x) is returned in the external integer signgam. The
argument x may not be a negative integer.
The following C program fragment might be used to calculate |¯:
if ((y = gamma(x)) > LNMAXDOUBLE)
error();
y = signgam * exp(y);
where LNMAXDOUBLE is the least value that causes exp to return a
range error, and is defined in the values.h header file.
DIAGNOSTICS
For negative integer arguments, HUGE is returned and errno is set to
EDOM. A message indicating SING error is printed on the standard
error output. When the -Xa or -Xc compilation options are used, a
divide by zero exception is raised.
If the correct value would overflow, gamma and lgamma return HUGE and
set errno to ERANGE.
For each of these functions, if x is a quiet NaN, that value is
returned. If x is a signaling NaN, a quiet NaN is returned and an
invalid operation exception is raised. In either case, errno is set
to EDOM, and a message indicating DOMAIN error is printed on the
standard error output.
When the -Xt compilation option is used, these error-handling
procedures may be changed with the function matherr.
When the -Xa or -Xc compilation options are used, HUGEVAL is
returned instead of HUGE, and no error messages are printed.
SEE ALSO
cc(1), exp(3M), matherr(3M), values(5), fpsetmask(3M).
Licensed material--property of copyright holder(s)