// testcomplex1.cpp
// g++ (GCC) では普通にコンパイルできる。
// c++ (LLVM) では -std=c++14 を指定する。
#include <iostream>
#include <complex>
std::complex<double> I(0.0,1.0);
using namespace std;
int main(void)
{
using namespace std::complex_literals;
complex<double> z(1.0, 2.0);
auto i=0.0+1.0i;
cout << "z=" << z << endl;
cout << "z.real()=" << z.real() << ", real(z)=" << real(z) << endl;
cout << "z.imag()=" << z.imag() << ", imag(z)=" << imag(z) << endl;
cout << "abs(z)=" << abs(z) << endl;
cout << "conj(z)=" << conj(z) << endl;
z=z*i;
cout << "z=" << z << endl;
cout << "z.real()=" << z.real() << ", real(z)=" << real(z) << endl;
cout << "z.imag()=" << z.imag() << ", imag(z)=" << imag(z) << endl;
cout << "abs(z)=" << abs(z) << endl;
cout << "conj(z)=" << conj(z) << endl;
z=z*I;
cout << "z=" << z << endl;
cout << "z.real()=" << z.real() << ", real(z)=" << real(z) << endl;
cout << "z.imag()=" << z.imag() << ", imag(z)=" << imag(z) << endl;
cout << "abs(z)=" << abs(z) << endl;
cout << "conj(z)=" << conj(z) << endl;
}
|