Difference between revisions of "CPP/STL/Complex"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with 'A complex number (a + bi). ==Complex.cpp== <source lang="cpp"> #include <iostream> #include <complex> int main (int argc, char *argv[]) { std::complex<double> a(3.4, 5.7); //…') |
(No difference)
|
Latest revision as of 21:13, 24 January 2011
A complex number (a + bi).
Complex.cpp
#include <iostream> #include <complex> int main (int argc, char *argv[]) { std::complex<double> a(3.4, 5.7); // 3.4 + 5.7i std::cout << a << std::endl; std::cout << std::conj(a) << std::endl; // complex conjugate std::cout << std::abs(a) << std::endl; // magnitude std::cout << std::real(a) << std::endl; // real part std::cout << std::imag(a) << std::endl; // imaginary part std::cout << std::norm(a) << std::endl; // norm (magnitude squared) return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Complex) ADD_EXECUTABLE(Complex Complex.cpp)