头文件:#include <math.h>
tanh() 用来求一个数的双曲正切值,其原型为:
double tanh(double x);
【参数】x 为双曲正切上的某点。
【返回值】返回 x 的双曲正切值,取值范围为 -1 到 1。
双曲正切的定义为 sinh(x)/cosh(x),即
双曲正切曲线示意图:
注意,使用 GCC 编译时请加入-lm。
请看下面的代码:
输出结果:
tanh(0.5) = 0.462117
tanh() 用来求一个数的双曲正切值,其原型为:
double tanh(double x);
【参数】x 为双曲正切上的某点。
【返回值】返回 x 的双曲正切值,取值范围为 -1 到 1。
双曲正切的定义为 sinh(x)/cosh(x),即
![](http://see.xidian.edu.cn/cpp/uploads/allimg/140624/1-140624150Z2217.png)
双曲正切曲线示意图:
![](http://see.xidian.edu.cn/cpp/uploads/allimg/140624/1-14062415032MW.png)
注意,使用 GCC 编译时请加入-lm。
请看下面的代码:
- #include <math.h>
- main(){
- double answer = tanh(0.5);
- printf("tanh(0.5) = %f\n", answer);
- }
#include <math.h> main(){ double answer = tanh(0.5); printf("tanh(0.5) = %f\n", answer); }
tanh(0.5) = 0.462117