Compute the arc cosine of a value.
The acos() function computes the principal value of the arc cosine (inverse cosine) of its argument. The argument must lie in the range [-1, 1]; values outside this range produce a domain error and the function returns NaN.
The result is expressed in radians and falls in the range [0, pi]. Together with asin() and atan2(), it forms the basic toolkit for inverse trigonometric calculations in C. Float and long double variants acosf() and acosl() are also provided.
The function is declared in <math.h>. It is widely used in geometry, computer graphics (e.g., computing angles between vectors via dot products), and physics simulations.
| Name | Description | Optional |
|---|---|---|
x |
The value whose arc cosine is computed. | No |
#include <math.h>
double a = acos(1.0); // 0
double b = acos(0.0); // pi/2 ~ 1.5708
double c = acos(-1.0); // pi ~ 3.1416