-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcomplex.hpp
43 lines (33 loc) · 1.11 KB
/
complex.hpp
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
#ifndef CPPEX_COMPLEX_COMPLEX_HPP
#define CPPEX_COMPLEX_COMPLEX_HPP
// Simple complex number class
class Complex {
public:
// Default value is zero
Complex() = default;
// Construct purely real complex
// Construct from real and imaginary parts
// Access components
double real() const;
double imag() const;
// Compute the complex conjugate
Complex conj();
// Compute the magnitude and squared magnitude
double norm() const;
double norm2() const;
// Declare comparisons
friend bool operator==(Complex const& a, Complex const& b);
friend bool operator!=(Complex const& a, Complex const& b);
// Declare binary arithmetic operators
friend Complex operator+(Complex const& a, Complex const& b);
friend Complex operator-(Complex const& a, Complex const& b);
friend Complex operator*(Complex const& a, Complex const& b);
friend Complex operator/(Complex const& a, Complex const& b);
// Question: how would you declare multiplication and division by a real number?
// Unary negation
friend Complex operator-(Complex const& a);
private:
double re = 0.0;
double im = 0.0;
};
#endif