C++ cmath tgamma() Function
Example
Return the gamma function of different numbers:
cout << tgamma(5.0) << "\n";
cout << tgamma(1.0) << "\n";
cout << tgamma(0.5);
Definition and Usage
The tgamma() function returns the value of the gamma function at x.
For a positive whole number n, tgamma(n) is the same as the factorial of n - 1 (all whole numbers from 1 to n - 1 multiplied together). For example, tgamma(5.0) is 1 * 2 * 3 * 4, which is 24. The gamma function also works for decimal numbers, like 0.5.
The tgamma function is defined in the <cmath> header file.
Tip: The gamma function grows very fast. Use lgamma() to get its logarithm, which also works for big numbers.
Syntax
tgamma(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. It should not be 0 or a negative whole number. |
Technical Details
| Returns: | A double value with the gamma function at x. |
|---|
Related Pages
Read more about math in our Math Tutorial.