cos
Compute the cosine of the input radian.
Interface Definition
C interface:
float cosf(float x);
double cos(double x);
long double cosl(long double x);
long double cosl_18(long double x);
cosl_18 is provided only in the high-precision version.
Fortran interface:
RES = COSF(X);
RES = COS(X);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of a radian angle. |
Input |
Return Value
- The cosine y of radian 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"
Fortran: "km.f03"
Examples
C interface:
double pi = acos(-1);
// typical usage
double a = pi/3, b = pi/2, c = -3*pi/4, d = 0.0;
// special handling
double e = INFINITY, f = -INFINITY, g = NAN;
double complex k = 0 + 0 * I;
// print result
printf("cos(pi/3) = %.15f\n", cos(a));
printf("cos(pi/2) = %.15f\n", cos(b));
printf("cos(-3*pi/4) = %.15f\n", cos(c));
printf("cos(0.0) = %.15f\n", cos(d));
printf("cos(INFINITY) = %.15f\n", cos(e));
printf("cos(-INFINITY) = %.15f\n", cos(f));
printf("cos(NAN) = %.15f\n", cos(g));
/*
* cos(pi/3) = 0.500000000000000
* cos(pi/2) = 0.000000000000000
* cos(-3*pi/4) = -0.707106781186547
* cos(0.0) = 1.000000000000000
* cos(INFINITY) = nan
* cos(-INFINITY) = nan
* cos(NAN) = nan
*
* */
Fortran interface:
REAL(8) :: X = 0.0
PRINT*, COS(X)
!
! OUTPUT
! 1.000000000000000
!
Parent topic: Function Syntax