HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)
l
lgamma(3M) lgamma(3M)
NAME
lgamma( ), lgammaf( ), lgammal( ), lgammaw( ), lgammaq( ), lgamma_r( ), lgammaf_r( ), lgammal_r( ),
lgammaw_r( ), lgammaq_r( ), gamma( ), gammaf( ), gammal( ), gammaw( ), gammaq( ), signgam - log
gamma functions
SYNOPSIS
#include <math.h>
double lgamma(double x);
double lgamma_r(double x, int *sign);
double gamma(double x);
extern int signgam;
Itanium(R)-based System Only
float lgammaf(float x);
long double lgammal(long double x);
extended lgammaw(extended x);
quad lgammaq(quad x);
float lgammaf_r(float x, int *sign);
long double lgammal_r(long double x, int *sign);
extended lgammaw_r(extended x, int *sign);
quad lgammaq_r(quad x, int *sign);
float gammaf(float x);
long double gammal(long double x);
extended gammaw(extended x);
quad gammaq(quad x);
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
tgamma() function, available on Itanium-based systems, can be used to calculate Γ(x). Or, the fol-
lowing 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 applica-
tions. The function lgamma_r() stores the sign of Γ(x) in the object pointed to by the second argument
sign. The value pointed to by sign is +1 if Γ(x) is positive, -1 if it is negative.
The
gamma() function is functionally equivalent to lgamma().
lgammaf(), gammaf(), and lgammaf_r() are float versions of lgamma(), gamma(), and
lgamma_r respectively; they take a float (first) argument and return a float result.
lgammal(), gammal(), and lgammal_r() are long double versions of lgamma(), gamma(),
and lgamma_r respectively; they take a long double (first) argument and return a long double
result.
lgammaw(), gammaw(), and lgammaw_r() are extended versions of lgamma(), gamma(), and
lgamma_r() respectively; they take an extended (first) argument and return an extended result.
Section 3−−564 Hewlett-Packard Company − 1 − HP-UX 11i Version 2: August 2003