I think you are looking for #include <complex>
for example:
std::complex<double> num(0,1);
In fact, you can use std::sqrt
with this type of complex
to calculate sqrt(-1)
:
#include <complex> #include <iostream> int main() { const std::complex<double> result = std::sqrt(std::complex<double>(-1,0)); std::cout << result << std::endl; }
For wn=exp((2*pi*i)/n)
you can do:
const double pi = std::acos(-1.0); const std::complex<double> i(0,1); std::complex<double> wn = std::exp((2*pi*i)/double(n));
source share