---
title: tanh
description: "计算输入弧度的双曲正切值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0175.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0175.html
indexId: e8342bc6b21f097eb2e23458e33770e1f524b3cf4154bda948e2ecda2e4c78a561
---
# tanh

计算输入弧度的双曲正切值。

#### 接口定义

C interface：

float tanhf(float x);

double tanh(double x);

long double tanhl(long double x);

Fortran interface：

RES = TANHF(X)

RES = TANH(X)


#### 参数

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


#### 返回值

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


#### 依赖

C: "km.h"


#### 示例

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
!
```
