我要评分
获取效率
正确性
完整性
易理解

cosd

Compute the cosine of the input degree.

Interface Definition

C interface:

float cosdf(float x);

double cosd(double x);

double cosd_18(double x);

long double cosdl(long double);

cosd_18 is provided only in the high-precision version.

Parameters

Parameter

Type

Description

Input/Output

x

  • For cosdf, x is of single-precision floating-point type.
  • For cosd and cosd_18, x is of double-precision floating-point type.
  • For cosdl, x is of long double-precision floating-point type.

Floating-point value of a degree angle.

Input

Return Value

  • The cosine y of degree x is returned. y ∈ [-1, +1]
  • If the input is +0, the return value is 1.
  • If the input is -0, the return value is 1.
  • If the input is ±∞, the return value is NaN.
  • If the input is ±NaN, the return value is ±NaN.

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    float x1 = 90.0, x2 = -90.0, x3 = 45.0, x4 = -45.0, x5 = 30.0, x6 = -30.0;
    float a = 0.0, b = INFINITY, c = -INFINITY, d = NAN;
    // print result
    printf("cosd(90.0) = %.15f\n", cosd(x1));
    printf("cosd(-90.0) = %.15f\n", cosd(x2));
    printf("cosd(45.0) = %.15f\n", cosd(x3));
    printf("cosd(-45.0) = %.15f\n", cosd(x4));
    printf("cosd(30.0) = %.15f\n", cosd(x5));
    printf("cosd(-30.0) = %.15f\n", cosd(x6));
    printf("cosd(0.0) = %.15f\n", cosd(a));
    printf("cosd(-0.0) = %.15f\n", cosd(-a));
    printf("cosd(INFINITY) = %.15f\n", cosd(b));
    printf("cosd(-INFINITY) = %.15f\n", cosd(c));
    printf("cosd(NAN) = %.15f\n", cosd(d));
    /* 
     * cosd(90.0) = 0.000000000000000
     * cosd(-90.0) = 0.000000000000000
     * cosd(45.0) = 0.707106781186548
     * cosd(-45.0) = 0.707106781186548
     * cosd(30.0) = 0.866025403784439
     * cosd(-30.0) = 0.866025403784439
     * cosd(0.0) = 1.000000000000000
     * cosd(-0.0) = 1.000000000000000
     * cosd(INFINITY) = nan
     * cosd(-INFINITY) = nan
     * cosd(NAN) = nan
     * 
     * */