Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
complx.cpp
Go to the documentation of this file.
1
29#include <complex>
30#include <utility>
31#include <iostream>
32
33#include <examples.h>
34
35typedef std::complex<double> dcomplex;
36
37// Return roots of a quadratic equation.
38std::pair<dcomplex, dcomplex>
40
41 dcomplex root = std::sqrt(b * b - 4.0 * a * c);
42 a = a * 2.0;
43 return std::make_pair ((-b + root) / a, (-b - root) / a);
44}
45
46
47int main () {
48
49 dcomplex a(2, 3);
50 dcomplex b(4, 5);
51 dcomplex c(6, 7);
52
53 std::pair<dcomplex, dcomplex> ans = quadratic(a, b, c);
54
55 std::cout << "Roots are " << ans.first << " and "
56 << ans.second << std::endl;
57
58 return 0;
59}
60
61
62
63
64
65
66
67
#define a
Definition 17.names.cpp:109
#define c
Definition 17.names.cpp:111
#define b
Definition 17.names.cpp:110
std::pair< dcomplex, dcomplex > quadratic(dcomplex a, dcomplex b, dcomplex c)
Definition complx.cpp:39
std::complex< double > dcomplex
Definition complx.cpp:35
int main()
Definition complx.cpp:47