English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Reference manual

C++ Library Function <cmath>

C ++The tanh() function usage and example

The function returns the hyperbolic tangent value of the angle represented in radians in<cmath>Header file definition.

[Math] tanh x = tanh(x) [C++]

tanh() prototype [from C ++ 11Standard beginning]

double tanh(double x);
float tanh(float x);
long double tanh(long double x);
double tanh(T x); //For integer

The tanh() function accepts a radian parameter and returns the hyperbolic tangent value of the angle in double, float, or long double type.

The hyperbolic tangent of x is:

The tanh() parameter

The tanh() function takes a mandatory parameter, representing the hyperbolic angle in radians.

The tanh() return value

The tanh() function returns the hyperbolic tangent of the parameter.

Example1The tanh() function in C ++How does it work?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double x = 0.50, result;
	result = tanh(x);
	cout << "tanh(x) = " << result << endl;
	double xDegrees = 90;
	x = xDegrees * 3.14159/180;
	result = tanh(x);
	cout << "tanh(x) = " << result << endl;
	return 0;
}

The output when running the program is:

tanh(x) = 0.462117
tanh(x) = 0.917152

Example2The tanh() function with integer type

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int x = 5;
	double result;
	result = tanh(x);
	cout << "tanh(x) = " << result << endl;
	return 0;
}

The output when running the program is:

tanh(x) = 0.999909

 C++ Library Function <cmath>