-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigIntFixed.h
More file actions
124 lines (99 loc) · 3.47 KB
/
BigIntFixed.h
File metadata and controls
124 lines (99 loc) · 3.47 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
118
119
120
121
122
123
// BigInt.h PAD
// entier de taille fixe sur <n> bit, n arbitrairement grand.
#pragma once
struct STQuickDiv;
class CBigIntFixed
{
protected:
// Little-endian : 0 : poids faible, 7 poids fort
UINT64 *m_TabVal;
// Taille en octets
int m_nSizeInByte;
public:
// constructeur. init a 0
CBigIntFixed(int nSizeInByte);
// constructeur. copie
CBigIntFixed(const CBigIntFixed &clSrc);
// destructeur
~CBigIntFixed();
// taille en bit
UINT nSizeInBit(void) const { return m_nSizeInByte*8; }
// taille en octets
int nSizeInByte(void) const { return m_nSizeInByte; }
// taille en I4 = mots de 4 octets = 32 bits
int nSizeInI4(void) const { return m_nSizeInByte/4; }
// taille en I8 = mots de 8 octets = 64 bits
int nSizeInI8(void) const { return m_nSizeInByte/8; }
// copie
void CopieFrom(const CBigIntFixed &clSrc);
const CBigIntFixed & operator= (const CBigIntFixed &clSrc);
const CBigIntFixed & 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 CBigIntFixed &clNombre2) const;
// init a 0
void SetToZero(void);
// = 0 ?
BOOL bIsZero(void) const;
// < 0 ?
BOOL bNegative(void) const;
//@@TEST
void InitFromInt256(const class CInt256 &clSrc);
// ---- 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) const;
// depuis une chaine en base 16
// ex : "1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD"
void FromStrHexa(PCXSTR pszVal);
// ---- opération mathématiques
// Addition
void Add(const CBigIntFixed &clVal2);
void AddI4(int nVal); // entier signé
// Soustraction
void Substract(const CBigIntFixed &clVal2 );
// négation : x = -x
void Negate(void);
// Multiplication
void Mult(const CBigIntFixed &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é
CBigIntFixed Pow2(void) const;
// Renvoie le cube
CBigIntFixed Pow3(void) const;
// Division entière de this
// ex : 2445 / 1000 => (2, 445)
void Divide(const CBigIntFixed &clDiviseur, OUT CBigIntFixed *pclDivision, OUT CBigIntFixed *pclclReste) const;
// division par 2
void DivideBy2(void);
// renvoie le modulo = reste de la divistion par <clDiviseur>
CBigIntFixed Modulo(const CBigIntFixed &clDiviseur) const;
// renvoie la valeur abosolue
CBigIntFixed Abs(void) const;
protected:
// constructeur helper
void _Init(int nSizeInByte);
// 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 et sa valeur dans cette puissance de 2.
// ex : "0x344A3" => 20,3
void _GetPow2AndCoef(OUT UINT32 *pnPow2, OUT UINT32 *pnCoef) const;
// renvoie les info pour effecter une division rapide appproximative par this
void _GetQuickDiv( OUT STQuickDiv *pstQuickDiv) const;
// Effectue une division rapide.
CBigIntFixed _clDivQuick(const struct STQuickDiv &stQuickDiv) const;
};