Format
#include <math.h> double cos(double x); float cosf(float x); long double cosl(long double x);float cos(float x);
long double cos(long double x);
Language Level: ANSI, POSIX, XPG4
cos calculates the cosine of x. The value x
is expressed in radians.
If x is too large, a partial loss of significance in the result may occur.
The absolute value of the argument x must be less than 263.
Note:
C++ prototypes
float cos(float x); long double cos(long double x);
are disabled when you compile using the lang(compatmath) option.
Return Value
cos returns the cosine of x.
If the absolute value of the argument is more than 263, then errno is set to EDOM and cos returns NaN.
Example
This example calculates y to be the cosine of
x.
#include <math.h> #include <stdio.h>
int main(void)
{
double x, y;
x = 7.2; y = cos(x);
printf("cos( %lf ) = %lf\n", x, y);
/***************************************
The output should be:
cos( 7.200000 ) = 0.608351 ***************************************/ }
![]()
acos -- Calculate Arccosine
cosh -- Calculate Hyperbolic Cosine
_facos -- Calculate Arccosine
_fcos -- Calculate Cosine
_fcossin -- Calculate Cosine and Sine
_fsincos -- Calculate Sine and Cosine
sin -- Calculate Sine
sinh -- Calculate Hyperbolic Sine
tan -- Calculate Tangent
tanh -- Calculate Hyperbolic Tangent
<math.h>
lang(compatmath) option
