---
title: tan
description: "计算实数的正切值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0115.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0115.html
indexId: 3d3d4a6ba6d56822c9c15404cd38f16b41ef8a0f8a67475b7b67ef9b5a74978574
---
# tan

计算实数的正切值。

#### 接口定义

C interface：

float tanf(float x);

double tan(double x);

float complex ctanf(float complex x);

double complex ctan(double complex x);

Fortran interface：

RES = TANF(X);

RES = TAN(X);

RES = CTANF(X);

RES = CTAN(X);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在tanf中，x是单精度浮点类型。 在tan中，x是双精度浮点类型。 在ctanf中，x是复数单精度浮点类型。 在ctan中，x是复数双精度浮点类型 | 表示弧度角的浮点值。 | 输入 |


#### 返回值

- 返回弧度角x的正切函数值y，y ∈ (-INF, +INF)。
- 输入+0，返回+0。
- 输入-0，返回-0。
- 输入±∞，返回nan。
- 输入nan，返回nan。

该函数在π(1/2 + n)处具有数学极点；没有通用的浮点表示能够精确地表示极点处的值，因此极点处会返回值，但不能认为是正确的。


#### 依赖

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;
double complex k = 0 + 0 * I;
// print result
printf("tan(pi/3) = %.15f\n", tan(a));
printf("tan(-3*pi/4) = %.15f\n", tan(c));
printf("tan(0.0) = %.15f\n", tan(d));
// mathematical poles
printf("tan(pi/2) = %.15f\n", tan(b));
printf("tan(INFINITY) = %.15f\n", tan(e));
printf("tan(-INFINITY) = %.15f\n", tan(f));
printf("tan(NAN) = %.15f\n", tan(g));
printf("ctan(0+0*I) = %.15f + %.15f * I\n", creal(ctan(k)), cimag(ctan(k)));
/*
*  tan(pi/3) = 1.732050807568877
*  tan(-3*pi/4) = 1.000000000000000
*  tan(0.0) = 0.000000000000000
*  tan(pi/2) = 16331239353195370.000000000000000
*  tan(INFINITY) = nan
*  tan(-INFINITY) = nan
*  tan(NAN) = nan
*  ctan(0+0*I) = 0 + 0 * I
*
* */
```

Fortran interface：

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