cosine function

You're viewing an older version of this page (#3319). View the current version.

View versions (4)

NAME

cos

INTERFACE

#include <math.h>

double cos ( double x ) long cosl ( long double x ) float cosf ( float x )

DESCRIPTION

The cos function computes the cosine of x (measured in radians). It returns a value in the range of -1 to 1:

Cos_500-1.gif
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  double result, x=0.5;
  result = cos(x);
  printf("The cos of %lf is %lf\n", x , result);
  return 0;
}
Output:
The cos of 0.500000 is 0.877583

SPECIAL VALUES

cos ( 0 ) returns 1.
cos ( &infin; ) returns a NaN and raises the invalid floating-point exception.

SEE ALSO

sin , tan , asin , acos , atan , atan2 , sinh , cosh , tanh

STANDARDS

The cos function conforms to ISO/IEC 9899:1999(E).