GAMMA(3M)GAMMA(3M) NAME gamma, lgamma, tgamma, lgammaf, tgammaf, lgammal, gammal, tgammal, signgam, signgaml, signgamf - Computes gamma/log gamma function and returns the sign of the function SYNOPSIS #include <math.h> double gamma(double x); double lgamma(double x); float lgammaf (float x); long double gammal(long double x); long double lgammal(long double x); double tgamma(double x); float tgammaf(float x); long double tgammal(long double x); extern int signgam; extern int signgaml; extern int signgamf; DESCRIPTION Alternate entries exist for several routines. The following lists these routines and the ANSI standard name and the alternate entry name: ANSI standard name Alternate name gammal qgamma lgammal qlgamma The tgamma functions and the lgammaf function are not available for programs compiled with the O32 ABI. lgamma and gamma return ln|GAMMA(x)| where GAMMA is the mathematical gamma function. gammal and lgammal are the long double versions of the log gamma function; lgamma is the float version. The tgamma functions return kappa gamma of x. The external integer signgam returns the sign of GAMMA(x), and the external integer signgaml returns the sign of GAMMAL(x). NOTES Do not use the following expression to compute g :=GAMMA(x): signgam * exp(gamma(x)) Instead, use a program similar to the following (in C): lg = gamma(x); g = signgam*exp(lg); Only after gamma has returned can signgam be correct. Note too that is a nonpositive integer. Analogous rules apply to gammal, signgaml and signgamf. The following C program fragment might be used to calculate G if the overflow needs to be detected: if ((y = gamma(x)) > LN_MAXDOUBLE) error(); y = signgam * exp(y); where LN_MAXDOUBLE is the least value that causes exp to overflow and is defined in the <values.h> header file. The name GAMMA was attached to log gamma only in the UNIX math library for C. Elsewhere (in some FORTRAN libraries) the name GAMMA belongs to G and the name ALGAMMA to log gamma in single precision; in double precision, the usual names are DGAMMA and DLGAMMA in FORTRAN. gamma in C originally delivered ln(G(x)). Later, the program gamma was changed to handle negative arguments in a more conventional way. The most recent changes correct inaccurate values when x is almost a negative integer. On SGI systems, the name gamma is currently maintained as a synonym to lgamma for compatibility. lgamma and gamma are not ANSI-C functions. If you compile with the -ansi or -ansiposix options, you must supply your own prototypes for these functions or you will get incorrect results. (See the prototypes defined in /usr/include/math.h). Long double operations on this system are only supported in round to nearest rounding mode (the default). The system must be in round to nearest rounding mode when calling any of the long double functions, or incorrect answers will result. RETURN VALUES Functions in the standard math library libm.a, are referred to as -lm versions. Those in the libmx library (libmx.a) are referred to as -lmx versions. Those in the the BSD math library (libm43.a) are referred to as -lm43 versions. The -lm and -lmx versions always return the default Quiet NaN and set errno to EDOM when a NaN is used as an argument. A NaN argument usually causes the -lm43 versions to return the same argument. The -lm43 versions never set errno. The value of HUGE_VAL is IEEE Infinity. The gamma functions return HUGE_VAL when the argument is zero or a negative integer. The -lm and -lmx versions also set errno to EDOM. When the correct value would overflow, the gamma functions return HUGE_VAL. The -lm and -lmx versions also set errno to ERANGE. See matherr(3M) for a description of error handling for -lmx functions. SEE ALSO math(3M), matherr(3M)