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

C++ tanh() 函数使用方法及示例

C++ Fonction de bibliothèque <cmath>

C ++中的tanh()函数返回以弧度表示的角度的双曲正切值。

该函数在<cmath>头文件中定义。

[数学] tanh x = tanh(x) [C++]

tanh()原型[从C ++ 11标准开始]

double tanh(double x);
float tanh(float x);
long double tanh(long double x);
double tanh(T x); //为整型

tanh()函数接受一个弧度参数,并以double、float或long double类型返回该角度的双曲正切值。

x的双曲正切是:

tanh()参数

tanh()函数采用一个强制性参数,以弧度表示双曲角。

tanh()返回值

tanh()函数返回参数的双曲正切值。

Exemple1:tanh()函数在C ++中如何工作?

#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;
}

Lors de l'exécution du programme, la sortie est :

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

Exemple2:具有整数类型的tanh()函数

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

Lors de l'exécution du programme, la sortie est :

tanh(x) = 0.999909

 C++ Fonction de bibliothèque <cmath>