C++ Standard Library C++ STL Library

C++ <complex> - pow() Function



The C++ <complex> pow() function returns the complex power of base x raised to a complex power y with a branch cut along the negative real axis for the first argument, as if computed by: exp(y*log(x)).

Syntax

template<class T> 
  complex<T> pow 
    (const complex<T>& x, int y);
template<class T> 
  complex<T> pow 
    (const complex<T>& x, const complex<T>& y);
template<class T> 
  complex<T> pow 
    (const complex<T>& x, const T& y);
template<class T> 
  complex<T> pow 
    (const T& x, const complex<T>& y);
template<class T> 
  complex<T> pow 
    (const complex<T>& x, const complex<T>& y);
template<class T> 
  complex<T> pow 
    (const complex<T>& x, const T& y);
template<class T> 
  complex<T> pow 
    (const T& x, const complex<T>& y);

Parameters

x Specify base as a complex value.
y Specify exponent as a complex value.

Return Value

Returns result of raising x to the power of y.

Example:

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

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

  //calculating z1 raised to the
  //power of z2
  cout<<"pow(z1, z2): "<<
      pow(z1, z2)<<"\n";


  return 0;
}

The output of the above code will be:

pow(z1, z2): (-0.863607,1.03689)

❮ C++ <complex> Library