
LGAMMA(3)                  UNIX Programmer's Manual                  LGAMMA(3)

NNAAMMEE
     llggaammmmaa - log gamma function

SSYYNNOOPPSSIISS
     ##iinncclluuddee <<mmaatthh..hh>>

     _d_o_u_b_l_e
     llggaammmmaa(_d_o_u_b_l_e _x)

DDEESSCCRRIIPPTTIIOONN
     Lgamma returns ln|(x)|.

     The external integer _s_i_g_n_g_a_m returns the sign of (x) .

IIDDIIOOSSYYNNCCRRAASSIIEESS
     Do _n_o_t 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 llggaammmmaa() has returned can signgam be correct.  Note too that
     (x) must overflow when x is large enough, underflow when -x is large
     enough, and spawn a division by zero when x is a nonpositive integer.

     Only in the UNIX math library for C was the name gamma ever attached to
     ln.  Elsewhere, for instance in IBM's FORTRAN library, the name GAMMA be-
     longs to  and the name ALGAMA to ln in single precision; in double the
     names are DGAMMA and DLGAMA. Why should C be different?

     Archaeological records suggest that C's _g_a_m_m_a originally delivered
     ln((|x|)).  Later, the program gamma was changed to cope with negative
     arguments x in a more conventional way, but the documentation did not re-
     flect that change correctly.  The most recent change corrects inaccurate
     values when x is almost a negative integer, and lets (x) be computed
     without conditional expressions.  Programmers should not assume that
     llggaammmmaa() has settled down.

     At some time in the future, the name _g_a_m_m_a will be rehabilitated and used
     for the gamma function, just as is done in FORTRAN. The reason for this
     is not so much compatibility with FORTRAN as a desire to achieve greater
     speed for smaller values of |x| and greater accuracy for larger values.

     Meanwhile, programmers who have to use the name _g_a_m_m_a in its former
     sense, for what is now llggaammmmaa(), have two choices:

     1.      Use the old math library, _l_i_b_o_m.

     2.      Add the following program to your others:

             #include <math.h>
             double gamma(x)
             double x;
             {
                     return (lgamma(x));
             }

DDIIAAGGNNOOSSTTIICCSS
     The reserved operand is returned on a VAX for negative integer arguments,
     _e_r_r_n_o is set to ERANGE; for very large arguments over/underflows will oc-
     cur inside the llggaammmmaa() routine.

SSEEEE AALLSSOO
     math(3),  infnan(3)

HHIISSTTOORRYY
     The llggaammmmaa function appeared in 4.3BSD.

4.3 Berkeley Distribution         May 6, 1991                                2





























































