Rate This Document
Findability
Accuracy
Completeness
Readability

cot

Compute the cotangent of the input radian.

Interface Definition

C interface:

float cotf(float x);

double cot(double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For cotf, x is of single-precision floating-point type.
  • For cot, x is of double-precision floating-point type.

Floating-point value of a radian angle.

Input

Return Value

  • Normal range: The cotangent y of radian x is returned, that is, y = cos(x)/sin(x). y ∈ [-∞, +∞]
  • If the input x = π * k (k is an integer), the output is ±inf.
  • If the input x = π * k + π/2 (k is an integer), the output is ±0.
  • If the input |x| = inf or NaN, the output is NaN.

Dependency

C: "km.h"

Example

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
     *
     * */