TGAMMA(3) Library Functions Manual TGAMMA(3)

tgamma, lgamma, gammagamma and log of gamma

#include <math.h>

double
tgamma(double x);

long double
tgammal(long double x);

float
tgammaf(float x);

double
lgamma_r(double x, int *psigngam);

long double
lgammal_r(long double x, int *psigngam);

float
lgammaf_r(float x, int *psigngam);

double
lgamma(double x);

long double
lgammal(long double x);

float
lgammaf(float x);

() calculates the gamma function of x. lgamma() calculates the natural logorithm of the absolute value of the gamma function of x. gamma() is the same function as tgamma. Its use is deprecated.

() is a thread-safe alternative to lgamma(). Instead of setting the global variable signgam, it stores the sign of Gamma(x) in the location pointed to by its second argument. In order to use the lgamma_r() function, define the macro _REENTRANT before including <math.h>.

tgamma(±0) returns ±infinity and raises the "divide-by-zero" floating-point exception.

(x) returns a NaN and raises the "invalid" floating-point exception if x is a negative integer.

(-infinity) returns a NaN and raises the "invalid" floating-point exception.

(+infinity) returns +infinity.

(x) generates a domain error if x is a negative integer or if the result cannnot be respresented when x is 0.

A range error may occur if the magnitude of x is too large or too small.

(1) returns +0.

(2) returns +0.

(x) returns +infinity and raises the "divide-by-zero" floating-point exception if x is a negative integer or 0.

(±infinity) returns +infinity.

(x) generates a range error if x is too large.

A range error may occur if x is a negative integer or 0.

(x) and its variants have the (non-threadsafe) side-effect of setting the global variable signgam to ±1, equal to the sign of tgamma(x). lgamma_r(x, psigngam) instead sets the user-allocated integer pointed to by the psigngam argument.

() and () are deprecated, and should not be used. The tgamma() function should be used instead. Note, however, that on some platforms, gamma() and gamma_r() historically computed the log of the Gamma function, instead of the Gamma function itself. When porting code from such platforms, it will be necessary to use lgamma() or lgamma_r() instead.

math(3)

The tgamma() , and lgamma() functions conform to ISO/IEC 9899:2011.

July 2, 2008