C++ Math tanh
The function calculates the hyperbolic tangent of an angle provided in radians.
Mathematically,
Syntax
Suppose the angle is 'x':
float tanh(float x);
double tanh(double x);
long double tanh(long double x);
double tanh(integral x);
Parameter
x : The value for which the hyperbolic tangent needs to be calculated.
Return value
It returns the hyperbolic tangent of x.
Example 1
Let's consider a straightforward scenario where the variable x is of type integer.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int degree =60;
float x = degree*3.14/180;
std::cout << "Value of degree is : " <<degree<< std::endl;
cout<<"tanh(x) : "<<tanh(x);
return 0;
}
Output:
Value of degree is : 60
tanh(x) : 0.780507
In this instance, the tanh(x) function calculates the hyperbolic tangent of x and yields a result of 0.78.
Example 2
Let's explore a basic scenario where the variable x holds a floating-point data type.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float degree = 45.2;
float x = degree*3.14/180;
std::cout << "Value of degree is : " <<degree<< std::endl;
cout<<"tanh(x) : "<<tanh(x);
return 0;
}
Output:
Value of degree is : 45.2
tanh(x) : 0.657552
In this instance, the tanh(x) function calculates the hyperbolic tangent of x, resulting in a value of 0.65.