C++ Complex Library - Polar


Advertisements

Description

It is a complex from polar components and rturns a complex object (in cartesian format) corresponding to the complex number defined by its polar components rho and theta, where rho is the magnitude (modulus) and theta is the phase angle.

Declaration

Following is the declaration for std::polar.

template<class T> complex<T> polar (const T& rho, const T& theta = 0);

C++11

	
template<class T> complex<T> polar (const T& rho, const T& theta = 0);

Parameters

  • rho It is a magnitude (modulus) of the complex number.

  • theta It is a phase angle (angular component) of the complex number.

  • T It is a type of the components of the complex type.

Return Value

It returns the complex cartesian equivalent to the polar format formed by rho and theta.

Exceptions

none

Example

In below example for std::polar.

#include <iostream>     
#include <complex>      

int main () {
   std::cout << "The complex whose magnitude is " << 1.0 << '\n';
   std::cout << " and phase angle is " << 0.7 << '\n';
   std::cout << " is " << std::polar (1.0, 0.7) << '\n';

   return 0;
}

The sample output should be like this −

The complex whose magnitude is 1
 and phase angle is 0.7
 is (0.764842,0.644218)
complex.htm
Advertisements