C++ Standard Library C++ STL Library

C++ <complex> - acos() Function



The C++ <complex> acos() function returns the complex arc cosine of a complex number z. It is a function on complex plane, and has two branch cuts:

  • Extends right from 1 along the real axis to ∞, continuous from below.
  • Extends left from -1 along the real axis to -∞, continuous from above.

Mathematically, it can be expressed as:

complex acos

For any z, acos(z) = 𝜋 - acos(-z)

Syntax

template<class T> complex<T> acos (const complex<T>& z);          

Parameters

z Specify the complex number.

Return Value

Returns the complex arc cosine of z.

Example:

The example below shows the usage of <complex> acos() function.

#include <iostream>
#include <complex>
using namespace std;
 
int main (){
  complex<double> z1 (2, 2);
  complex<double> z2 (2, 0);
  complex<double> z3 (0, 2);

  //calculate the complex arc cosine
  cout<<"acos(z1): "<<acos(z1)<<"\n";
  cout<<"acos(z2): "<<acos(z2)<<"\n";
  cout<<"acos(z3): "<<acos(z3)<<"\n";

  return 0;
}

The output of the above code will be:

acos(z1): (0.816547,-1.73432)
acos(z2): (0,-1.31696)
acos(z3): (1.5708,-1.44364)

❮ C++ <complex> Library