C++ Math tgamma
The tgamma function calculates the gamma function value of the input argument provided to the function.
Suppose a number is x:
Syntax
float tgamma(float x);
double tgamma(double x);
long double tgamma(long double x);
double tgamma(double x);
Parameter
x : It is a floating point value.
Return value
It returns the gamma function value of x.
| Parameter | Return value |
|---|---|
| x = ±0 | ±∞ |
| x = -ve | nan |
| x = -∞ | nan |
| x = +∞ | +∞ |
| x = nan | nan |
Example 1
Let's examine a straightforward example where x equals zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 0.0;
cout<<"Value of x is : "<<x<<'\n';
cout<<"tgamma(x) : "<<tgamma(x);
return 0;}
Output:
Value of x is : 0
tgamma(x) : inf
When x equals zero in the example provided, the function tgamma will result in positive infinity.
Example 2
Let's examine a basic scenario where the value of x is below zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= -6;
cout<<"Value of x is : "<<x<<'\n';
cout<<"tgamma(x) : "<<tgamma(x);
return 0;
}
Output:
Value of x is : -6
tgamma(x) : nan
When x is a negative integer in the given scenario, the tgamma function will yield a result of NaN.
Example 3
Let's consider a basic scenario where the value of x approaches negative infinity.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= -9.0/0.0;
cout<<"Value of x is : "<<x<<'\n';
cout<<"tgamma(x): "<<tgamma(x);
return 0;
}
Output:
Value of x is : -inf
tgamma(x): nan
When x tends to negative infinity in the given scenario, the value of x is negative infinity. Consequently, the function tgamma will output a nan (not a number).
Example 4
Let's consider a basic scenario where the value is positive infinity.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 7.8/0.0;
cout<<"Value of x is : "<<x<<'\n';
cout<<"tgamma(x) : "<<tgamma(x);
return 0;
}
Output:
Value of x is : inf
tgamma(x) : inf
In the provided illustration, the value of x is positive infinity. Consequently, the tgamma function yields positive infinity.
Example 5
Let's consider a basic scenario where the value of x is NaN.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 0.0/0.0;
cout<<"Value of x is : "<<x<<'\n';
cout<<"tgamma(x) : "<<tgamma(x);
return 0;
}
Output:
Value of x is : -nan
tgamma(x) : -nan
In the previous example, the variable x is set to NaN. Consequently, the tgamma function will yield NaN as a result.