Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cmath> acos() function returns arc cosine of a value. The return value will be in the range 0 through 𝜋.

Note: acos() is the inverse of cos().

Syntax

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);
//additional overloads for integral types
double acos (T x);         

Parameters

x Specify the value in range [-1, 1].

Return Value

Returns the arc cosine of the value.
If the x is not in the range of [-1, 1], domain error occurs.

Example:

In the below example, acos() function is used to find out the arc cosine of a given value.

#include <iostream>
#include <cmath>
using namespace std;
 
int main () {
  cout<<acos(0.5)<<"\n";
  cout<<acos(1)<<"\n";
  cout<<acos(2)<<"\n";
  return 0;
}

The output of the above code will be:

1.0472
0
nan

❮ C++ <cmath> Library