-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex.cpp
56 lines (50 loc) · 861 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
45
46
47
48
49
50
51
52
53
54
55
56
#include "complex.hpp"
void Complex::correctComplex()
{
if(_real < LOWER && _real > -LOWER)
{
_real = 0;
}
if(_imaginary < LOWER && _imaginary > -LOWER)
{
_imaginary = 0;
}
}
Complex::Complex()
{
_imaginary = 0;
_real = 0;
}
Complex::Complex(const double re, const double im)
{
_imaginary = im;
_real = re;
correctComplex();
}
double Complex::getRe() const{return _real;}
double Complex::getIm() const{return _imaginary;}
Complex Complex::conjugate()
{
return Complex(_real, -_imaginary);
}
Complex Complex::pow(unsigned int power)
{
Complex result = *this;
if(power == 0)
{
result = Complex(1, 0);
}
else
{
for(unsigned int iter = 0; iter < power - 1; ++iter)
{
result = *this * result;
}
}
result.correctComplex();
return result;
}
void Complex::print() const
{
std::cout << _real << " + " << _imaginary << "*i ";
}