cos() Calculate Cosine
#include <math.h>
double cos(x); Cosine
double x; Radians
cos() returns the cosine of 'x' radians.
Returns: Cosine of 'x'. If 'x' is large, a partial loss of
significance in the result may occur, in which case
matherr() is called with a PLOSS error, 'errno' (defined
in <stdlib.h>) is set to ERANGE (defined in <math.h>),
and the partially insignificant result is returned. If
'x' is so large that a total loss of significance occurs,
then matherr() is called with a TLOSS error, a TLOSS
error message is printed to 'stderr', 'errno' is set to
ERANGE, and 0.0 is returned.
Notes: PLOSS first occurs at 'x' greater than 1.0E8.
TLOSS first occurs at 'x' greater than 2.0E9.
Error handling can be modified by using the matherr()
function.
-------------------------------- Example ---------------------------------
The following statements print the cosine of pi radians and 5.2e8 pi
radians, and check for any loss of significance.
#include <math.h> /* for cos() and ERANGE */
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for errno */
main()
{
double cosine, pi = 3.1415926535;
cosine = cos(pi);
printf("cosine of pi = %e\n", cosine);
errno = 0;
cosine = cos(5.2e8 * pi);
/*if a TLOSS error occurs, a message is also printed to stderr*/
if (errno == ERANGE)
printf("ERANGE error in cos()\n");
printf("cosine of 5.2e8 * pi = %e\n", cosine);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster