LGAMMA

Section: C Library Functions (3)
Index Return to Main Contents

BSD mandoc
BSD 4.3  

NAME

lgamma - log gamma function  

SYNOPSIS

Fd #include <math.h> Ft double Fn lgamma double x  

DESCRIPTION

Lgamma returns ln|Gamma(x)|.

The external integer Fa signgam returns the sign of Gamma(x) .  

IDIOSYNCRASIES

Do not use the expression ``signgam*exp(lgamma(x)) '' to compute g := Gamma(x). Instead use a program like this (in C):
lg = lgamma(x); g = signgam*exp(lg);

Only after Fn lgamma has returned can signgam be correct. Note too that Gamma(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 lnGamma. Elsewhere, for instance in IBM 's FORTRAN library, the name GAMMA belongs to Gamma and the name ALGAMA to lnGamma in single precision; in double the names are DGAMMA and DLGAMA Why should C be different?

Archaeological records suggest that C's gamma originally delivered ln(Gamma(|x|)). Later, the program gamma was changed to cope with negative arguments x in a more conventional way, but the documentation did not reflect that change correctly. The most recent change corrects inaccurate values when x is almost a negative integer, and lets Gamma(x) be computed without conditional expressions. Programmers should not assume that Fn lgamma has settled down.

At some time in the future, the name gamma 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 gamma in its former sense, for what is now Fn lgamma , have two choices:

  1. Use the old math library, libom
  2. Add the following program to your others:
    #include <math.h>
    double gamma(x)
    double x;
    {
    return (lgamma(x));
    }
    
     

    DIAGNOSTICS

    The reserved operand is returned on a VAX for negative integer arguments, errno is set to Er ERANGE ; for very large arguments over/underflows will occur inside the Fn lgamma routine.  

    SEE ALSO

    math(3), infnan(3)  

    HISTORY

    The function appeared in BSD 4.3


     

    Index

    NAME
    SYNOPSIS
    DESCRIPTION
    IDIOSYNCRASIES
    DIAGNOSTICS
    SEE ALSO
    HISTORY

    This document was created by man2html, using the manual pages.
    Time: 08:43:27 GMT, September 19, 2022