Rate This Document
Findability
Accuracy
Completeness
Readability

cosd

Compute the cosine of a real number. The input parameter is an angle.

Interface Definition

C interface:

float cosdf(float x);

Parameters

Parameter

Type

Description

Input/Output

x

For cosdf, x is of single-precision floating-point type.

Floating-point value of an angle

Input

Return Value

  • The cosine y of angle 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.

Dependencies

C: "km.h"

Examples

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