-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcmplx.h
More file actions
41 lines (32 loc) · 767 Bytes
/
cmplx.h
File metadata and controls
41 lines (32 loc) · 767 Bytes
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
#ifndef PATHSIM_CMPLX_HPP
#define PATHSIM_CMPLX_HPP
namespace PathSim {
struct cmplx {
double r { 0. };
double i { 0. };
void set(double r, double i) { this->r = r; this->i = i; }
double l2() const { return r * r + i * i; }
cmplx& operator+=(const cmplx &rhs) {
this->r += rhs.r;
this->i += rhs.i;
return *this;
}
cmplx& operator*=(const double rhs) {
this->r *= rhs;
this->i *= rhs;
return *this;
}
};
static inline cmplx operator*(const cmplx &lhs, const cmplx &rhs)
{
return cmplx{
lhs.r * rhs.r - lhs.i * rhs.i,
lhs.r * rhs.i + lhs.i * rhs.r
};
}
static inline cmplx operator*(const cmplx &lhs, const double rhs)
{
return cmplx{ lhs.r * rhs, lhs.i * rhs };
}
} // namespace PathSim
#endif // PATHSIM_CMPLX_HPP