function
<cmath> <ctgmath>

cos

double cos (double x);
     double cos  (double x);
      float cosf (float x);
long double cosl (long double x);
     double cos (double x);
      float cos (float x);
long double cos (long double x);
     double cos (double x);
      float cos (float x);
long double cos (long double x);
     double cos (T x);           // additional overloads for integral types
Compute cosine
Returns the cosine of an angle of x radians.

Header <tgmath.h> provides a type-generic macro version of this function.
This function is overloaded in <complex> and <valarray> (see complex cos and valarray cos).
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

This function is also overloaded in <complex> and <valarray> (see complex cos and valarray cos).

Parameters

x
Value representing an angle expressed in radians.
One radian is equivalent to 180/PI degrees.

Return Value

Cosine of x radians.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* cos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* cos */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 60.0;
  result = cos ( param * PI / 180.0 );
  printf ("The cosine of %f degrees is %f.\n", param, result );
  return 0;
}


Output:

The cosine of 60.000000 degrees is 0.500000.

See also