function
<cmath> <ctgmath>

acos

double acos (double x);
     double acos  (double x);      float acosf (float x);long double acosl (long double x);
     double acos (double x);      float acos (float x);long double acos (long double x);
     double acos (double x);      float acos (float x);long double acos (long double x);     double acos (T x);          // additional overloads for integral types
Compute arc cosine
Returns the principal value of the arc cosine of x, expressed in radians.

In trigonometrics, arc cosine is the inverse operation of cosine.

Header <tgmath.h> provides a type-generic macro version of this function.
This function is overloaded in <valarray> (see valarray acos).
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

This function is also overloaded in <complex> and <valarray> (see complex acos and valarray acos).

Parameters

x
Value whose arc cosine is computed, in the interval [-1,+1].
If the argument is out of this interval, a domain error occurs.

Return Value

Principal arc cosine of x, in the interval [0,pi] radians.
One radian is equivalent to 180/PI degrees.

If a domain error occurs, the global variable errno is set to EDOM.
If a domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* acos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* acos */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = acos (param) * 180.0 / PI;
  printf ("The arc cosine of %f is %f degrees.\n", param, result);
  return 0;
}

Output:

The arc cosine of 0.500000 is 60.000000 degrees.


See also