Math Tgamma Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Tgamma Function

Math Tgamma Function

BLUF: Mastering Math Tgamma Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Tgamma Function

C++ is renowned for its efficiency. Learn how Math Tgamma Function enables low-level control and high-performance computing in the tutorial below.

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

Example

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.

Example

#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:

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.

Example

#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:

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.

Example

#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:

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.

Example

#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:

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.

Example

#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:

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.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience