function template
std::polar
<complex>
template<class T> complex<T> polar (const T& rho, const T& theta = 0);
Return complex from polar components
Returns 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. The values in the return value are the same as if:
1 2
|
real = rho * cos(theta);
imag = rho * sin(theta);
|
Parameters
- rho
- Magnitude (modulus) of the complex number.
T is complex<T>'s template type (i.e., its value type).
- theta
- Phase angle (angular component) of the complex number.
T is complex<T>'s template type (i.e., its value type).
Return value
The complex cartesian equivalent to the polar format formed by
rho and
theta.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// polar example
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
cout << "The complex whose magnitude is " << 2.0;
cout << " and phase angle is " << 0.5;
cout << " is " << polar (2.0, 0.5) << endl;
return 0;
}
|
Output:
The complex whose magnitude is 2 and phase angle is 0.5 is (1.75517,0.958851)
|
See also
- abs
- Return absolute value of complex (function template
)
- arg
- Return phase angle of complex (function template
)