cos Functions

Description

Calculate the cosine (cos and _cosl) or hyperbolic cosine (cosh and _coshl).

#include <math.h>

double cos( double x );

double cosh( double x );

long double _cosl( long double x );

long double _coshl( long double x );

x Angle in radians  

Remarks

The cos and cosh functions return the cosine and hyperbolic cosine, respectively, of x.

The _cosl and _coshl functions are the 80-bit counterparts and use the 80-bit, 10-byte coprocessor form of arguments and return values. See the reference page on the long double functions for more details on this data type.

Return Value

If x is large, a partial loss of significance in the result may occur in a call to cos, in which case the function generates a _PLOSS error. If x is so large that significance is completely lost, cos prints a _TLOSS message to stderr and returns 0. In both cases, errno is set to ERANGE.

If the result is too large in a cosh call, the function returns HUGE_VAL and sets errno to ERANGE. This behavior can be changed with _matherr.

Compatibility

cos, cosh

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_cosl, _coshl

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

acos functions, asin functions, atan functions, _matherr, sin functions, tan functions

Example

/* SINCOS.C: This program displays the sine, hyperbolic sine, cosine,

* and hyperbolic cosine of pi / 2.

*/

#include <math.h>

#include <stdio.h>

void main( void )

{

double pi = 3.1415926535;

double x, y;

x = pi / 2;

y = sin( x );

printf( "sin( %f ) = %f\n", x, y );

y = sinh( x );

printf( "sinh( %f ) = %f\n",x, y );

y = cos( x );

printf( "cos( %f ) = %f\n", x, y );

y = cosh( x );

printf( "cosh( %f ) = %f\n",x, y );

}

Output

sin( 1.570796 ) = 1.000000

sinh( 1.570796 ) = 2.301299

cos( 1.570796 ) = 0.000000

cosh( 1.570796 ) = 2.509178