tanh(x)函数详解

首页 / C++入门教程 / tanh(x)函数详解

该函数计算以弧度表示的角度的双曲正切值。

数学上

tanhx = ex -e-x/ ex+e-x

tanh - 语法

假设角度为" x":

float tanh(float x);
double tanh(double x);
long double tanh(long double x);
double tanh(integral x);

tanh - 参数

x :要计算其双曲正切值的值。

tanh - 返回值

它返回x的双曲正切。

tanh - 例子1

让我们看一下x的值为整数类型的简单示例。

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

输出:

Value of degree is : 60
tanh(x) : 0.780507   

在此示例中,tanh(x)函数计算x的双曲正切值并返回值0.78。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-tanh-function.html

来源:LearnFk无涯教程网

tanh - 例子2

让我们看一下x的值为浮点型的简单示例。

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

输出:

Value of degree is : 45.2
tanh(x) : 0.657552   

在此示例中,tanh(x)函数计算x的双曲正切值并返回值0.65。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

Android开发高手课 -〔张绍文〕

软件工程之美 -〔宝玉〕

RPC实战与核心原理 -〔何小锋〕

OAuth 2.0实战课 -〔王新栋〕

张汉东的Rust实战课 -〔张汉东〕

大厂晋升指南 -〔李运华〕

林外 · 专利写作第一课 -〔林外〕

AI大模型之美 -〔徐文浩〕

好记忆不如烂笔头。留下您的足迹吧 :)