-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigInt.h
More file actions
118 lines (92 loc) · 3.09 KB
/
BigInt.h
File metadata and controls
118 lines (92 loc) · 3.09 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// BigInt.h PAD
// entier de taille fixe sur <n> bit, n arbitrairement grand.
#pragma once
static const int nSizeInByte = 32;
static const int nSizeI4 = 8; // 32 * 8 = 256
static const int nSizeI8 = 4; // 64 * 4 = 256
class CBigIntFixed
{
protected:
// Little-endian : 0 : poids faible, 7 poids fort
UINT64 m_TabVal;
// Taille en octets
int m_nSizeInByte;
public:
// init a 0
CBigInt(int nSizeInByte);
// init a 0
void _InitZero(int nSizeInByte);
// init a partir d'un entier non signé
CBigInt(int nSizeInByte, UINT64 nVal );
// init a partir d'un entier signé
CBigInt(int nSizeInByte, INT32 nVal);
// copie
CBigInt(int nSizeInByte, const CInt256 &clSrc);
// taille en I4
int nSizeInI4(void) const { return m_nSizeInByte/4;}
// taille en I8
int nSizeInI4(void) const { return m_nSizeInByte/8; }
// copie
void CopieFrom(const CInt256 &clSrc);
const CInt256 & operator= (const CInt256 &clSrc);
const CInt256 & operator= (UINT64 nVal);
// comparation non signée < = >.
// renvoie -1 si onest < a clNombre2. 0 si égal. 1 si on est supérieur
int nCompareU(const CInt256 &clNombre2) const;
// init a 0
void SetToZero(void);
BOOL bIsZero(void) const;
BOOL bNegative(void) const;
// ---- convertions ----
// depuis un INT64
void FromUI8(UINT64 nVal);
// init a partir d'un entier signé
void FromI4(INT32 nVal);
// vers un INT64
UINT64 nToUI8(void) const;
// depuis une chaine en base 10.
// ex : "32670510020758816978083085130507043184471273380659243275938904335757337482424"
void FromStrBase10(PCXSTR pszVal);
// vers une chaine en base 10.
// nLenInChar doit faire au moins 79 charatères.
void ToStrBase10(OUT PXSTR pszVal, int nLenInChar);
// depuis une chaine en base 16
// ex : "1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD"
void FromStrHexa(PCXSTR pszVal);
// ---- opération mathématiques
// Addition
void Add(const CInt256 &clVal2);
void AddI4(int nVal); // entier signé
// Soustraction
void Substract(const CInt256 &clVal2 );
// négation : x = -x
void Negate(void);
// Multiplication
void Mult(const CInt256 &clVal2);
// Multiplication par un entier 32
void MultUI32(UINT32 nVal);
// Multiplication par une puissance de 2 (décalage de bits)
void MultPow2(int nPow2);
// Renvoie le carré
CInt256 Pow2(void) const;
// Renvoie le cube
CInt256 Pow3(void) const;
// Division entière de this
// ex : 2445 / 1000 => (2, 445)
void Divide(const CInt256 &clDiviseur, OUT CInt256 *pclDivision, OUT CInt256 *pclclReste) const;
// division par 2
void DivideBy2(void);
// renvoie le modulo = reste de la divistion par <clDiviseur>
CInt256 Modulo(const CInt256 &clDiviseur) const;
// renvoie la valeur abosolue
CInt256 Abs(void) const;
protected:
// renvoie le n°eme mot de 3é bits. 0 poids faible
UINT32 _nGetI4(int nNumMot) const;
void _SetI4(int nNumMot, UINT32 nVal );
// utilitaires pour la division
// renvoie la magnitude. cad la puisance de 2 max du nombre
int _nGetMagnitudeEtDivisteurRapide(OUT UINT32 *pnQuickDivisor) const;
// Effectue une division rapide.
CInt256 _clDivQuick(UINT32 nQuickDivisor, int nMagnitude) const;
};