acos Function

Calculates the trigonometric arc cosine function of a double precision floating-point value.

Include

<math.h>

Prototype

double acos(double x);

Argument

 x value between -1 and 1 for which to return the arc cosine

Return Value

Returns the arc cosine of x in the range [0, π] radians (inclusive) or NaN if a domain error occurs.

Remarks

If x is less than -1 or greater than 1, a domain error will occur and errno will be set to EDOM.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
double x,y;

errno = 0;
x = -2.0;
y = acos (x);
if (errno)
perror("Error");
printf("The arccosine of %f is %f\n", x, y);

errno = 0;
x = 0.10;
y = acos (x);
if (errno)
perror("Error");
printf("The arccosine of %f is %f\n", x, y);
}

Example Output

Error: Domain error
The arccosine of -2.000000 is nan
The arccosine of 0.100000 is 1.470629