-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexModClass.h
68 lines (63 loc) · 1.36 KB
/
ComplexModClass.h
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
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#ifndef COMPLEXMODCLASS_H
#define COMPLEXMODCLASS_H
#include "ComplexCoreClass.h"
TemplateDefinition
class ComplexModClass : ComplexCoreClass <TemplateParameter>
{
public:
ComplexModClass()
{
// dont call base class default constructor directly, icc has problem with it.
// default constructor of base class automatically called befor constructor of derived class.
// but parametrized constructor of base class should be called explicitly.
}
ComplexModClass(MemoryManagerClass *MemoryManager) : BaseConstructor
{
}
Ts Mod(Ts X, Ts Y)
{
Ts n = floor(X / Y);
Ts m = X - (n*Y);
return m;
}
Ts* Mod(Ts* X, int XLength, Ts Division)
{
if (XLength <= 0)
return NULL;
Ts* m = this->AllocMem_Single(XLength);
for (int i = 0; i < XLength; i++)
{
m[i] = Mod(X[i], Division);
}
return m;
}
Ta Mod(Ta X, Ts Division)
{
Ta res(this->MemManager);
if (X.Length <= 0)
{
return res;
}
res.SetArray(Mod(X.GetArray(), X.Length, Division), X.Length);
return res;
}
void Mod_inplace(Ts* X, int XLength, Ts Division)
{
if (XLength <= 0)
return;
for (int i = 0; i < XLength; i++)
{
X[i] = Mod(X[i], Division);
}
}
void Mod_inplace(Ta X, Ts Division)
{
if (X.Length <= 0)
{
return;
}
Mod_inplace(X.GetArray(), X.Length, Division);
}
};
#endif