gamma(3M) 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
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.
Errors
For non-positive integer arguments, a value that will compare
equal to +HUGE_VAL is returned and errno is set to EDOM. On
systems that support IEEE exceptions, the divide by zero
exception is raised.
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.
Copyright 1994 Novell, Inc. Page 1
gamma(3M) gamma(3M)
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.
REFERENCES
cc(1), exp(3M), matherr(3M), values(5)
Copyright 1994 Novell, Inc. Page 2