I want to represent sqrt(-1) in C++, because I am trying to implement an FFT algorithm. Is there a good way of representing this?
I guess you're looking for #include <complex> e.g.:
std::complex<double> num(0,1);
You can actually use std::sqrt with this complex type to compute 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With