C <math.h> - tgamma() Function
The C <math.h> tgamma() function returns gamma function of the argument. The gamma function of x is defined as:
Syntax
double tgamma (double x); float tgammaf (float x); long double tgammal (long double x);
Parameters
x |
Specify the value. |
Return Value
- If no errors occur, returns gamma function of the argument.
- If a domain error occurs, an implementation-defined value (NaN where supported) is returned.
- 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.
- If a range error due to underflow occurs, the correct value (after rounding) is returned.
Example:
The example below shows the usage of tgamma() function.
#include <stdio.h> #include <math.h> int main (){ printf("tgamma(0.1): %lf\n", tgamma(0.1)); printf("tgamma(1.5): %lf\n", tgamma(1.5)); printf("tgamma(2.5): %lf\n", tgamma(2.5)); printf("tgamma(-1.5): %lf\n", tgamma(-1.5)); printf("tgamma(-2.5): %lf\n", tgamma(-2.5)); return 0; }
The output of the above code will be:
tgamma(0.1): 9.513508 tgamma(1.5): 0.886227 tgamma(2.5): 1.329340 tgamma(-1.5): 2.363272 tgamma(-2.5): -0.945309
❮ C <math.h> Library