---
title: tan
description: "计算输入弧度的正切值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0115.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0115.html
indexId: de6ff110fdaa9ecbe30ebe7383ce103e7872861b7b2709f74cde4e068cf0a52a76
---
# tan

计算输入弧度的正切值。

#### 接口定义

C interface：

float tanf(float x);

double tan(double x);

long double tanl(long double x);

Fortran interface：

RES = TANF(X);

RES = TAN(X);


#### 参数

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


#### 返回值

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

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


#### 依赖

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;
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));
/*
*  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
*
* */
```

Fortran interface：

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