Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gamma(3M) — HP-UX 10.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exp(3M)

isinf(3M)

isnan(3M)

values(5)

lgamma(3M)

NAME

lgamma(), lgamma_r(), gamma(), signgam() − log gamma function

SYNOPSIS

#include <math.h>

double lgamma(double x);

double gamma(double x);

extern int signgam;

double lgamma_r(double x, int *sign);

DESCRIPTION

lgamma() and gamma() return ln(|Γ(x)|) , where Γ(x) is defined as the integral, as t goes from zero to infinity, of exp(−t) times t to the power (x−1).

The sign of Γ(x) is returned in the external integer signgam.  The argument x must not be zero or a negative integer.  (lgamma() is defined over the reals excluding the non-positive integers.) 

The following C program fragment can be used to calculate Γ(x):

if ((y = lgamma(x)) > LN_MAXDOUBLE)
        error();
y = signgam * exp(y);

where if y is greater than LN_MAXDOUBLE, as defined in the <values.h> header file, exp() returns a range error (see exp(3M)).

The log gamma function lgamma() is not reentrant, because it uses the global variable signgam.  The function lgamma_r() is a reentrant version of lgamma() that can be used in multi-threaded applications. The function lgamma_r() returns the sign of Γ(x) in its parameter list, through the pointer sign. The value pointed to by sign is +1 if Γ(x) is positive, −1 if it is negative. The function lgamma_r() is named in the spirit of the POSIX threads draft standard (P1003.4a), but it has no formal sanction. 

To use these functions, link in the math library by specifying −lm on the compiler or linker command line. 

RETURN VALUE

If x is a non-positive integer, lgamma() and gamma() return HUGE_VAL. 

If the correct value would overflow, lgamma() and gamma() return HUGE_VAL. 

If the correct value after rounding would be smaller in magnitude than MINDOUBLE, lgamma() and gamma() return zero. 

If x is NaN, lgamma() and gamma() return NaN. 

ERRORS

No errors are defined. 

WARNINGS

lgamma() and gamma() are unsafe in multi-thread applications.  lgamma_r() is MT-Safe and should be used instead. 

SEE ALSO

exp(3M), isinf(3M), isnan(3M), values(5). 

STANDARDS CONFORMANCE

lgamma(): SVID3, XPG4.2

gamma(): SVID2, XPG4.2

signgam: SVID3, XPG4.2

Hewlett-Packard Company  —  HP-UX Release 10.20:  July 1996

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026