-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexNum.cpp
55 lines (39 loc) · 1.09 KB
/
ComplexNum.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
#include "ComplexNum.h"
// Êîíñòðóêòîð êîìïëåêñíîãî ÷èñëà
CComplexNum::CComplexNum():cnumber(0.0, 0.0){}
// Ìåòîä óñòàíîâêè êîìïëåêñíîãî ÷èñëà
void CComplexNum::SetComplexNum(double re,double im)
{
cnumber.real(re);
cnumber.imag(im);
}
// Ìåòîä ÷òåíèÿ ÷àñòåé êîìïëåêñíîãî ÷èñëà
void CComplexNum::GetComplexNum(double &re,double &im)
{
re = cnumber.real();
im = cnumber.imag();
}
// Ìåòîä ñëîæåíèÿ êîìïëåêñíûõ ÷èñåë
void CComplexNum::AddComplexNum(double re,double im)
{
cnumber += std::complex<double>(re, im);
}
// Ìåòîä óìíîæåíèÿ êîìïëåêñíûõ ÷èñåë
void CComplexNum::MulComplexNum(double re,double im)
{
cnumber *= std::complex<double>(re, im);
}
// Ìåòîä ïðåîáðàçîâàíèÿ êîìïëåêñíîãî ÷èñëà â êëþ÷
void CComplexNum::ComplexNumToCode(unsigned char *Code)
{
const unsigned SIZE = 8;
unsigned i;
unsigned char *p{ nullptr };
double realpart{ cnumber.real() }, imagepart{ cnumber.imag() };
p = reinterpret_cast<unsigned char *>(&realpart);
for(i = 0; i < SIZE; ++i)
Code[i] = p[i];
p = reinterpret_cast<unsigned char *>(&imagepart);
for(i = 0; i < SIZE; ++i)
Code[i+8] = p[i];
}