Chapter Contents

Previous

Next
cos

cos



Compute the Trigonometric Cosine

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
DIAGNOSTICS
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


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 . 60 degrees   */
      /*  is pi/3 radians.                     */
   y = cos(M_PI/3);

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


RELATED FUNCTIONS

sin , tan , _matherr


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.