Share via


cos, cosh

Calculate the cosine (cos) or hyperbolic cosine (cosh).

doublecos(doublex**);**

doublecosh(doublex**);**

Routine Required Header Compatibility
cos <math.h> ANSI, Win 95, Win NT
cosh <math.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

The cos and cosh functions return the cosine and hyperbolic cosine, respectively, of x. If x is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result of a call to cos occurs, in which case the function generates a _TLOSS error and returns an indefinite (same as a quiet NaN).

If the result is too large in a cosh call, the function returns HUGE_VAL and sets errno to ERANGE. You can modify error handling with _matherr.

Parameter

x

Angle in radians

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

Floating-Point Support Routines

See Also   acos, asin, atan, _matherr, sin, tan