Std::complex
complex 클래스는 템플릿 클래스이다. 복소수와 복소수 연산들이 필요할 때 사용하면 된다.
Imaginary number
허수 i
를 표현하는 방법은 아래와 같다.
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> dcomp;
int main()
{
dcomp i;
dcomp a;
double pi;
pi = 2 * asin(1);
i = -1;
i = sqrt(i);
a = exp(2*pi*i);
cout << "i is " << i << "and Euler was right: e(i pi) = " << a << endl;
return 0;
}