Facebook Page Twitter Page LinkedIn Page
× C Standard Library

The C <math.h> lgamma() function returns the natural logarithm of the absolute value of gamma function (log gamma function) of the argument. The log gamma function of x is defined as:



double lgamma (double x);
float lgammaf (float x);
long double lgammal (long double x);            


x Specify the value.

Return Value

  • If no errors occur, returns gamma function of the argument.
  • If a pole error occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned.
  • If a range error due to overflow occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned.


The below example shows the usage of lgamma() function.

#include <stdio.h>
#include <math.h>
int main (){
  printf("lgamma(0.1): %lf\n", lgamma(0.1));
  printf("lgamma(1.5): %lf\n", lgamma(1.5));
  printf("lgamma(2.5): %lf\n", lgamma(2.5));
  printf("lgamma(-1.5): %lf\n", lgamma(-1.5));
  printf("lgamma(-2.5): %lf\n", lgamma(-2.5));
  return 0;

The output of the above code will be:

lgamma(0.1): 2.252713
lgamma(1.5): -0.120782
lgamma(2.5): 0.284683
lgamma(-1.5): 0.860047
lgamma(-2.5): -0.056244

❮ C <math.h> Library