cos
Compute the cosine of a real number.
Interface Definition
C interface:
float cosf(float x);
double cos(double x);
float complex ccosf(float complex x);
double complex ccos(double complex x);
Fortran interface:
RES = COSF(X);
RES = COS(X);
RES = CCOSF(X);
RES = CCOS(X);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of a radian angle |
Input |
Return Value
- The cosine y of radiant 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));
printf("ccos(0+0*I) = %.15f + %.15f * I\n", creal(ccos(k)), cimag(ccos(k)));
/*
* 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
* ccos(0+0*I) = 1 + -0 * I
*
* */
Fortran interface:
REAL(8) :: X = 0.0
PRINT*, COS(X)
!
! OUTPUT
! 1.000000000000000
!
Parent topic: Function Syntax