---
title: tanh
description: "计算实数的双曲正切值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0243.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0243.html
indexId: be52e30f5b5b34c1559fdf3c5c20a4a2ae73cb8759b2f82dd8435cfb3581ea9874
---
# tanh

计算实数的双曲正切值。

#### 接口定义

C interface：

float tanhf(float x);

double tanh(double x);

Fortran interface：

RES = TANHF(X)

RES = TANH(X)


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在tanhf中，x是单精度浮点类型。 在tanh中，x是双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

- 返回弧度角x的双曲正切函数值y，y ∈ [-1, +1]。
- 输入+0，返回+0。
- 输入-0，返回-0。
- 输入+∞，返回+1。
- 输入-∞，返回-1。
- 输入nan，返回nan。


#### 依赖

C: "km.h"

Fortran: "km.f03"


#### 示例

C interface：

```
double pi = acos(-1);
// typical usage
double a = pi/3, c = -3*pi/4, d = 0.0;
// special handling
double b = pi/2, e = INFINITY, f = -INFINITY, g = NAN;
// print result
printf("tanh(pi/3) = %.15f\n", tanh(a));
printf("tanh(-3*pi/4) = %.15f\n", tanh(c));
printf("tanh(0.0) = %.15f\n", tanh(d));
// mathematical poles
printf("tanh(pi/2) = %.15f\n", tanh(b));
printf("tanh(INFINITY) = %.15f\n", tanh(e));
printf("tanh(-INFINITY) = %.15f\n", tanh(f));
printf("tanh(NAN) = %.15f\n", tanh(g));
/*
*  tanh(pi/3) = 0.780714435359268
*  tanh(-3*pi/4) = -0.982193380007239
*  tanh(0.0) = 0.000000000000000
*  tanh(pi/2) = 0.917152335667274
*  tanh(INFINITY) = 1.000000000000000
*  tanh(-INFINITY) = -1.000000000000000
*  tanh(NAN) = nan
*
* */
```

Fortran interface：

```
REAL(8) :: X = 0.0
PRINT*,  TANH(X)
!
! OUTPUT
!     0.000000000000000
!
```
