C Math tgamma() Function
Example
Return the gamma function of different numbers:
printf("%f\n", tgamma(5.0));
printf("%f\n", tgamma(1.0));
printf("%f", 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 <math.h> header file.
Tip: The gamma function grows very fast. Use lgamma() to get its logarithm, which also works for big numbers.
Syntax
double tgamma(double x);
There are also versions for float and long double values: tgammaf() and tgammal().
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 C Math Tutorial.