---
title: cot
description: "计算输入弧度的三角余切值，输入参数为弧度。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0169.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0169.html
indexId: 90c59500e545c2bc3de2415efc9a786d6a128c3d25f048de633d6560445bac7f61
---
# 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
     *
     * */
```
