---
title: cotd
description: "计算输入角度的三角余切值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0662.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0662.html
indexId: 3df4c66709f9462779b7a317e308f8c7b2ea9f4cd64b22a5f5727e90101aa1b576
---
# cotd

计算输入角度的三角余切值。

#### 接口定义

C interface：

float cotdf(float x);

double cotd(double x);

long double cotdl(long double x);


#### 参数

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


#### 返回值

- 正常区间：返回角度x的余切函数值y = cot(x * π / 180)，y ∈ [-∞, +∞]。
- 输入x = 180 * k，（k为整数），输出为±inf。
- 输入x = 180 * k + 90，（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("cotd(1.0) = %.15f\n", cotd(x1));
printf("cotd(-1.0) = %.15f\n", cotd(x2));
printf("cotd(0.5) = %.15f\n", cotd(x3));
printf("cotd(-0.5) = %.15f\n", cotd(x4));
printf("cotd(0.0) = %.15f\n", cotd(a));
printf("cotd(-0.0) = %.15f\n", cotd(-a));
printf("cotd(INFINITY) = %.15f\n", cotd(b));
printf("cotd(-INFINITY) = %.15f\n", cotd(c));
printf("cotd(NAN) = %.15f\n", cotd(d));
/*
*  cotd(1.0) = -57.289961630759421
*  cotd(-1.0) = 57.289961630759421
*  cotd(0.5) = 114.588650129309613
*  cotd(-0.5) = -114.588650129309613
*  cotd(0.0) = inf
*  cotd(-0.0) = -inf
*  cotd(INFINITY) = nan
*  cotd(-INFINITY) = nan
*  cotd(NAN) = nan
*
* */
```
