C++ cmath lgamma() Function
Example
Return the logarithm of the gamma function at 5:
cout << lgamma(5.0) << "\n";
cout << log(tgamma(5.0));
Definition and Usage
The lgamma() function returns the natural logarithm of the absolute value of the gamma function at x. It gives the same result as log(abs(tgamma(x))).
The gamma function grows very fast, and can get too big for a double. Its logarithm stays small, so lgamma() also works for big values of x, like 1000.
The lgamma function is defined in the <cmath> header file.
Tip: See tgamma() to learn more about the gamma function.
Syntax
lgamma(double x)
The function also works with float and long double values. Then it returns a value of the same type.
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. A number. |
Technical Details
| Returns: | A double value with the natural logarithm of the absolute value of the gamma function at x. |
|---|
Related Pages
Read more about math in our Math Tutorial.