#include <iostream>
#include <complex>
#include <cmath>
int main () {
float theta = 45;
float theta_pi = theta*(M_PI/180);
std::cout << " is " << std::polar (1.0f, theta_pi) << '\n';
return 0;
}
#include <iostream>
#include <complex>
#include <cmath>
int main () {
double theta = 45;
double theta_pi = theta*(M_PI/180);
std::complex<double> rst;
std::complex<double> I = std::complex<double>(0.0f, 1.0f);
rst = cos(theta_pi) + I*sin(theta_pi);
std::cout << " is " << rst << '\n';
return 0;
}
- 3.角度转复指数,使用C库<complex.h>中的_Complex_I
#include <iostream>
#include <complex.h>
#include <cmath>
int main () {
float theta = 45;
float theta_pi = theta*(M_PI/180);
std::cout << " is " << std::exp(_Complex_I * theta_pi);
return 0;
}
#include <iostream>
#include <complex>
#include <cmath>
int main () {
float theta = 45;
float theta_pi = theta*(M_PI/180);
std::cout << " is " << std::exp(std::complex<float>(0, 1) * theta_pi);
return 0;
}