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

计算实数的反正切值。

#### 接口定义

C interface：

float atanf(float x);

double atan(double x);

float complex catanf(float complex x);

double complex catan(double complex x);

Fortran interface：

RES = ATANF(X)

RES = ATAN(X)

RES = CATANF(X)

RES = CATAN(X)


#### 参数

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


#### 返回值

- 返回(-π/2,π/2)上正切值等于x的那个唯一确定的角，取值范围为(-π/2, +π/2)。
- 输入+0，返回+0。
- 输入-0，返回-0。
- 输入+∞，返回+π/2。
- 输入-∞，返回-π/2。
- 输入nan，返回nan。


#### 依赖

C: "km.h"

Fortran: "km.f03"


#### 示例

C interface：

```
double pi = acos(-1);
// typical usage
double a = pi/3, c = -3*pi/4, b = pi/2;
// special handling
double d = +0.0, h = -0.0, e = INFINITY, f = -INFINITY, g = NAN;
double complex k = 0 + 0 * I;
// print result
printf("atan(pi/3) = %.15f\n", atan(a));
printf("atan(-3*pi/4) = %.15f\n", atan(c));
printf("atan(pi/2) = %.15f\n", atan(b));
printf("atan(+0.0) = %+.15f\n", atan(d));
printf("atan(-0.0) = %+.15f\n", atan(h));
printf("atan(INFINITY) = %+.15f\n", atan(e));
printf("atan(-INFINITY) = %+.15f\n", atan(f));
printf("atan(NAN) = %.15f\n", atan(g));
printf("catan(0+0*I) = %.15f + %.15f * I\n", creal(catan(k)), cimag(catan(k)));
/*
*  atan(pi/3) = 0.808448792630022
*  atan(-3*pi/4) = -1.169422824815756
*  atan(pi/2) = 1.003884821853887
*  atan(+0.0) = +0.000000000000000
*  atan(-0.0) = -0.000000000000000
*  atan(INFINITY) = +1.570796326794897
*  atan(-INFINITY) = -1.570796326794897
*  atan(NAN) = nan
*  catan(0+0*I) = 0 + 0 * I
*
* */
```

Fortran interface：

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