cos -- Compute the Trigonometric Cosine

SYNOPSIS

 #include <math.h>

 double cos(double x);
 

DESCRIPTION

cos computes the trigonometric cosine of the value x. The cos function expects a value of x expressed in radians.

Because the cosine function is periodic, only the value of x mod 2 pi is used to compute the cosine. If x is very large, only a limited precision is left to represent x mod 2 pi. Thus, an error message is written for very large negative or positive arguments (see DIAGNOSTICS below).

RETURN VALUE

cos returns the value of the cosine of the argument x, provided that this value is defined and computable. The return value is of type double.

DIAGNOSTICS

For a very large argument (x> 6.7465e9), the function returns 0.0. In this case, the message "total loss of significance" is also written to stderr (the standard error file).

If an error occurs in cos, the _matherr routine is called. You can supply your own version of _matherr to suppress the diagnostic message or modify the value returned.

EXAMPLE

This example computes the cosine of a 60-degree angle using cos:
  #include <stdio.h>
  #include <lcmath.h>

  main()
  {
     double y;

        /* The constant M_PI is declared in the  */
        /*  header file <lcmath.h>. 60 degrees   */
        /*  is pi/3 radians.                     */
     y = cos(M_PI/3);

     printf("cos(%f) =  %fn",M_PI,y);
  }

 

RELATED FUNCTIONS

sin, tan, _matherr

SEE ALSO

Mathematical Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.