function
<cmath> <ctgmath>

lgamma

     double lgamma  (double x);      float lgammaf (float x);long double lgammal (long double x);
     double lgamma (double x);      float lgamma (float x);long double lgamma (long double x);     double lgamma (T x);           // additional overloads for integral types
Compute log-gamma function
log-gamma function Returns the natural logarithm of the absolute value of the gamma function of x.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Parameter for the log-gamma function.

Return Value

Log-gamma function of x.
If x is too large, an overflow range error occurs.
If x is zero or a negative integer for which the function is asymptotic, it may cause a pole error (depending on implementation).

If an overflow range error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_OVERFLOW is raised.

If a pole error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_DIVBYZERO is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* lgamma example */
#include <stdio.h>      /* printf */
#include <math.h>       /* lgamma */

int main ()
{
  double param, result;
  param = 0.5;
  result = lgamma (param);
  printf ("lgamma(%f) = %f\n", param, result );
  return 0;
}

Output:

lgamma (0.500000) = 0.572365


See also