---
title: cot
description: "计算输入弧度的三角余切值，输入参数为弧度。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0661.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0661.html
indexId: 15218ca92a2cdcb9090ecfd102b03e6c53c359a29ae2eebec85a99093502724476
---
# cot

计算输入弧度的三角余切值，输入参数为弧度。

#### 接口定义

C interface：

float cotf(float x);

double cot(double x);

long double cotl(long double x);


#### 参数

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


#### 返回值

- 正常区间：返回弧度角x的余切函数值y = cos(x) / sin(x)，y∈[-∞, +∞]。
- 输入x = π * k，（k为整数），输出为±inf。
- 输入x = π * k + π/2，（k为整数），输出为±0。
- 输入|x| = inf or nan，输出为nan。


#### 依赖

C: "km.h"


#### 示例

C interface：
```
// typical usage
float x1 = -1.0, x2 = 1.0, x3 = 0.5, x4 = -0.5;
// special handling
float a = 0.0, b = INFINITY, c = -INFINITY, d = NAN;
// print result
printf("cot(1.0) = %.15f\n", cot(x1));
printf("cot(-1.0) = %.15f\n", cot(x2));
printf("cot(0.5) = %.15f\n", cot(x3));
printf("cot(-0.5) = %.15f\n", cot(x4));
printf("cot(0.0) = %.15f\n", cot(a));
printf("cot(-0.0) = %.15f\n", cot(-a));
printf("cot(INFINITY) = %.15f\n", cot(b));
printf("cot(-INFINITY) = %.15f\n", cot(c));
printf("cot(NAN) = %.15f\n", cot(d));
/*
*  cot(1.0) = -0.642092615934331
*  cot(-1.0) = 0.642092615934331
*  cot(0.5) = 1.830487721712452
*  cot(-0.5) = -1.830487721712452
*  cot(0.0) = inf
*  cot(-0.0) = -inf
*  cot(INFINITY) = nan
*  cot(-INFINITY) = nan
*  cot(NAN) = nan
*
* */
```
