A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_complex_polar.htm below:

C++ Complex::polar() function

C++ Complex::polar() function

The C++ std::complex::polar() function is a utility for creating a complex number from a polar coordinates. It takes two arguments: one is magnitude and another is an angle(in radians). It returns the complex object representing the complex number corresponding to the specified polar coordinates.

Syntax

Following is the syntax for std::complex::polar() function.

polar (const T& rho, const T& theta = 0);
Parameters Return Value

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

Exceptions

none

Example 1

In the following example, we are going to comsider the basic usage of the polar() function.

#include <iostream>
#include <complex>
int main() {
   std::complex < double > x = std::polar(1.2, M_PI / 4);
   std::cout << "Result: " << x << std::endl;
   return 0;
}
Output

Output of the above code is as follows −

Result: (0.848528,0.848528)
Example 2

Consider the following example, where we are going to create a complex number with 60degrees.

#include <iostream>
#include <complex>
int main() {
   std::complex < double > x = std::polar(2.1, M_PI / 3);
   std::cout << "Result : " << x << std::endl;
   return 0;
}
Output

If we run the above code it will generate the following output −

Result : (1.05,1.81865)
Example 3

Let's look at the following example, where we are going to create a complx number using negative angle.

#include <iostream>
#include <complex>
int main() {
   std::complex < double > x = std::polar(1.5, -M_PI / 6);
   std::cout << "Result: " << x << std::endl;
   return 0;
}
Output

Following is the output of the above code −

Result: (1.29904,-0.75)

complex.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4