tgamma() method in C/C++ with Examples

04 Oct, 2021
The tgamma() function is defined in header math.h header in C and cmath library in C++. This function is used to compute the gamma function of an argument passed to the function.Syntax:  
float tgamma(float x);  
double tgamma(double x);  
long double tgamma(long double x);  
Parameters: This method accepts a parameter x which is the value whose gamma function is to be computed. It can be float, double or long double.Return Value: This function returns the gamma function value of x.  
For x = 0: +inf/-inf
For x = -inf: NAN
For x = +inf: +inf
For x = -ve: NAN
For x = NAN: NAN
Errors: There are two types of errors that usually occur with tgamma() method:  
Range errors: Overflow range error: This occurs when the magnitude of the parameter x is very large.Underflow range error: This occurs when the magnitude of the parameter x is very small.Domain/Pole errors: If x is zero or a negative integer for which the function is asymptotic, it may cause a domain error or a pole error (or none, depending on implementation).
Range errors: Overflow range error: This occurs when the magnitude of the parameter x is very large.Underflow range error: This occurs when the magnitude of the parameter x is very small.
Overflow range error: This occurs when the magnitude of the parameter x is very large.
Underflow range error: This occurs when the magnitude of the parameter x is very small.
Domain/Pole errors: If x is zero or a negative integer for which the function is asymptotic, it may cause a domain error or a pole error (or none, depending on implementation).
If x is zero or a negative integer for which the function is asymptotic, it may cause a domain error or a pole error (or none, depending on implementation).
Below examples demonstrate the use of tgamma() function in C/C++: 
CPP
// C++ program to show the// use of tgamma() method #include <cmath>#include <iostream>using namespace std; // Driver codeint main(){     // Example 1    float x = 0.0;    cout << "For x = " << x         << ", tgamma(x) = "         << tgamma(x) << endl;     // Example 2    x = -18.0 / 0.0;    cout << "For x = " << x         << ", tgamma(x) = "         << tgamma(x) << endl;     // Example 3    x = 10.0 / 0.0;    cout << "For x = " << x         << ", tgamma(x) = "         << tgamma(x) << endl;     // Example 4    x = 0.0 / 0.0;    cout << "For x = " << x         << ", tgamma(x) = "         << tgamma(x);     return 0;}
For x = 0, tgamma(x) = inf
For x = -inf, tgamma(x) = nan
For x = inf, tgamma(x) = inf
For x = -nan, tgamma(x) = -nan
 
Reference: http://www.cplusplus.com/reference/cmath/tgamma/ 
sagartomar9927
C-Functions
CPP-Functions
cpp-math
math
C Language
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Unordered Sets in C++ Standard Template Library
Operators in C / C++
Exception Handling in C++
What is the purpose of a function prototype?
Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
Vector in C++ STL
Map in C++ Standard Template Library (STL)
Initialize a vector in C++ (7 different ways)
Set in C++ Standard Template Library (STL)
Priority Queue in C++ Standard Template Library (STL)