-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplex.cpp
37 lines (28 loc) · 913 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
//
// Created by Андрей Москалёв on 12.12.2019.
//
#include "Complex.h"
Complex::Complex(double r, double i) {
this->real = r;
this->imag = i;
}
Complex::Complex() {
this->real = 0;
this->imag = 0;
}
Complex Complex::operator+(Complex const &obj) const {
return {real + obj.real, imag + obj.imag};
}
Complex Complex::operator-(Complex const &obj) const {
return {real - obj.real, imag - obj.imag};
}
Complex Complex::operator*(Complex const &obj) const {
return {real * obj.real - imag * obj.imag, real * obj.imag + imag * obj.real};
}
Complex Complex::operator/(Complex const &obj) const {
return {(real * obj.real + imag * obj.imag) / (obj.real * obj.real + obj.imag * obj.imag),
(imag * obj.real - real * obj.imag) / (obj.real * obj.real + obj.imag * obj.imag)};
}
double Complex::pointRadius() {
return sqrt(real * real + imag * imag);
}