C <math.h> - lgamma() Function
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:
Syntax
double lgamma (double x); float lgammaf (float x); long double lgammal (long double x);
Parameters
x |
Specify the value. |
Return Value
- If no errors occur, returns the natural logarithm of the absolute value of 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.
Example:
The example below 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