forked from EPCCed/APT-CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex.cpp
44 lines (32 loc) · 786 Bytes
/
complex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "complex.hpp"
#include <cmath>
double const& Complex::real() {
return re;
}
double Complex::imag() const {
return im;
}
Complex Complex::conj() const {
return Complex{re, -im};
}
double Complex::norm() const {
return std::sqrt(norm2());
}
double Complex::norm2() const {
return re*re + im*im;
}
bool operator==(Complex const& a, Complex const& b) {
return (a.re == b.re) && (a.im == b.re);
}
bool operator!=(Complex const& a, Complex const& b) {
return !(a == b);
}
Complex operator+(Complex const& a, Complex const& b) {
return Complex{a.re + b.re, a.im + b.im};
}
Complex operator*(Complex const& a, Complex const& b) {
// (a + ib)*(c + id) == (a*c - b*d) + i(b*c + a*d)
}
Complex operator-(Complex const& a) {
return Complex{-a.re, -a.im};
}