gamma(3M)

lgamma, gamma, lgammal, gammal - log gamma function

As shipped in IRIX 6.5.5. Last changed in IRIX 6.5.5.

NAME
     lgamma, gamma, lgammal, gammal - log gamma function

SYNOPSIS
     #include <math.h>

     double gamma(double x);
     double lgamma(double x);
     long double gammal(long double x);
     long double lgammal(long double x);

     extern int signgam;
     extern int signgaml;

IMPLEMENTATION
     IRIX systems

DESCRIPTION
     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.

     gamma and lgamma are identical, as are gammal and lgammal.

     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
     GAMMA(x) must overflow when x is large enough, and is undefined when x
     is a nonpositive integer.

     Analogous rules apply to gammal and signgaml.

     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 ln G only in the UNIX math library for
     C.   Elsewhere (in some FORTRAN libraries) the name GAMMA belongs to G
     and the name ALGAMMA to ln G 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.

     Some math libraries have changed the name of this function to lgamma()
     to suggest its real functionality.

     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).

RETURN VALUES
     Functions in the standard math library libm.a, are referred to as -lm
     versions.  Those in math 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)

     This man page is available only online.