# gamma(3m) [bsd man page]

LGAMMA(3M) LGAMMA(3M)NAME

lgamma - log gamma functionSYNOPSIS

#include <math.h> double lgamma(x) double x;DESCRIPTION

_ Lgamma returns ln|| (x)|. _ The external integer signgam returns the sign of | (x) .IDIOSYNCRASIES

_ Do not 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 lgamma has returned can signgam be correct. Note too that | (x) must overflow when x is large enough, underflow whenis large enough, and spawn a division by zero when x is a nonpositive integer. _ Only in the UNIX m_th library for C was the na_e gamma ever attached to ln| . Elsewhere, for instance in IBM's FORTRAN library, the name GAMMA belongs 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 gamma 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 _ot reflect that change correctly. The most recent change corrects inac- curate values when x is almost a negative integer, and lets | (x) be computed without conditional expressions. Programmers should not assume that 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 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)); }-xDIAGNOSTICS

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

math(3M), infnan(3M)4.3 Berkeley DistributionMay 12, 1986 LGAMMA(3M)

## Check Out this Related Man Page

LGAMMA(3) BSD Library Functions Manual LGAMMA(3)NAME

lgamma, lgammaf, lgamma_r, lgammaf_r, gamma, gammaf, gamma_r, gammaf_r, tgamma, tgammaflog gamma function--LIBRARY

Math Library (libm, -lm)SYNOPSIS

#include <math.h> extern int signgam; double lgamma(double x); float lgammaf(float x); double lgamma_r(double x, int *sign); float lgammaf_r(float x, int *sign); double gamma(double x); float gammaf(float x); double gamma_r(double x, int *sign); float gammaf_r(float x, int *sign); double tgamma(double x); float tgammaf(float x);DESCRIPTION

_ lgamma(x) returns ln|| (x)|. _ The external integer signgam returns the sign of | (x). _ lgamma_r() is a reentrant interface that performs identically to lgamma(), differing in that the sign of | (x) is stored in the location pointed to by the sign argument and signgam is not modified. _ The tgamma(x) and tgammaf(x) functions return | (x), with no effect on signgam. gamma(), gammaf(), gamma_r(), and gammaf_r() are deprecated aliases for lgamma(), lgammaf(), lgamma_r(), and lgammaf_r(), respectively.IDIOSYNCRASIES

_ Do not 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 lgamma() has returned can signgam be correct.RETURN VALUES

lgamma() returns appropriate values unless an argument is out of range. Overflow will occur for sufficiently large positive values, and non- positive integers. For large non-integer negative values, tgamma() will underflow. On the VAX, the reserved operator is returned, and errno is set to ERANGE.SEE ALSO

math(3)HISTORY

The lgamma function appeared in 4.3BSD. The tgamma() function appeared in NetBSD 6.0.BSD

May 4, 2012 BSD