C++ Math tanh
The function computes the hyperbolic tangent of an angle given in radian.
Mathematically,
Syntax
Suppose the angle is 'x':
Example
float tanh(float x);
double tanh(double x);
long double tanh(long double x);
double tanh(integral x);
Parameter
x : The value whose hyperbolic tangent is to be computed.
Return value
It returns the hyperbolic tangent of x.
Example 1
Let's see the simple example when the value of x is integer type.
Example
#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:
Output
Value of degree is : 60
tanh(x) : 0.780507
In this example, tanh(x) function computes the hyperbolic tangent of x and returns the value 0.78.
Example 2
Let's see the simple example when the value of x is float type.
Example
#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:
Output
Value of degree is : 45.2
tanh(x) : 0.657552
In this example, tanh(x) function computes the hyperbolic tangent of x and returns the value 0.65.