LGAMMA(3) BSD Programmer's Manual LGAMMA(3)NAME
lgamma, lgammaf, gamma, gammaf, lgamma_r, lgammaf_r, gamma_r, gammaf_r -
log gamma functions, gamma functions
SYNOPSIS
#include <math.h>
extern int signgam;
double
lgamma(double x);
float
lgammaf(float x);
double
gamma(double x);
float
gammaf(float x);
double
lgamma_r(double x, int *sign);
float
lgammaf_r(float x, int *sign);
double
gamma_r(double x, int *sign);
float
gammaf_r(float x, int *sign);
DESCRIPTION _
lgamma(x) and lgammaf(x) return ln|| (x)|.
_
The external integer signgam returns the sign of | (x).
_
gamma(x) and gammaf(x) return | (x), with no effect on signgam.
The functions lgamma_r(), lgammaf_r(), gamma_r() and gammaf_r() are iden-
tical to the versions without the _r suffixes, but instead of setting the
global variable signgam, they store the sign indirectly through their
sign argument. This avoids any races between asynchronous threads to set
a global variable like signgam.
IDIOSYNCRASIES
D_ not use the expression ``signgam*exp(lgamma(x))'' to compute g :=
| (x). Instead use a program like this (in C):
lg = lgamma(x); g = signgam*exp(lg);
Only after lgamma() or lgammaf() has returned can signgam be correct.
For arguments in its range, gamma() and gammaf() is preferred, as for
positive arguments it can be more accurate. Exponentiation of lgamma()
may lose several significant bits.
ERRORS
If the result would overflow, then:
_IEEE_ The return value is +Inf.
_POSIX_ Same as _IEEE_, but errno is also set to ERANGE.
_XOPEN_ Same as _POSIX_, but errno is only set if matherr(3) returns 0.
The exception type is OVERFLOW.
_SVID_ Same as _XOPEN_, but the return value is MAXFLOAT.
If x is a nonpositive integer value, then:
_IEEE_ The return value is +Inf.
_POSIX_ Same as _IEEE_, but errno is also set to EDOM.
_XOPEN_ Same as _POSIX_, but errno is only set if matherr(3) returns 0.
The exception type is SING.
_SVID_ Same as _XOPEN_, but the return value is MAXFLOAT, and a mes-
sage is printed to stderr if errno is set.
SEE ALSOmath(3)HISTORY
The lgamma function appeared in 4.3BSD. The gamma function appeared in
4.4BSD. The name gamma() was originally dedicated to the lgamma() func-
tion, so some old code may no longer be compatible.
4.3 Berkeley Distribution February 17, 1998 2