forked from evdenis/mini-gmp
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbigint.h
206 lines (156 loc) · 9.97 KB
/
bigint.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//#
//# Copyright (C) 2018-2021 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef BIGINT_H
#define BIGINT_H
#include "mini-gmp.h"
#include <string>
#include <vector>
#include "minigmp_global.h"
/**
* @brief The BigInt class - c++ minigmp wrapper
*/
class MINIGMPSHARED_EXPORT BigInt
{
mpz_t data;
public:
BigInt();
BigInt(const BigInt& val, int bitCount = -1);
BigInt(const std::string &imput, int base = 10);
BigInt(intMpz val);
BigInt(char item, unsigned int size, int base);
std::string getString(int base = 10) const;
~BigInt();
BigInt& powm(const BigInt &pow, const BigInt &mod);
static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
BigInt& pow(uIntMpz pow);
BigInt& log(int base);
/**
* @brief sizeBits
* @return size of bits in memory
*/
int sizeBits() const;
int sizeBytes() const;
/**
* @brief longBits
* @return current length in Bits of number
*/
int longBits() const;
int longBytes() const;
int sizeType() const;
bool isPrime(bool absalut = false) const;
BigInt& gcd(const BigInt &a, const BigInt &b);
void fromHex(const std::string& hex);
/**
* @brief bigPow10
* @param pow
* @return number 10 ^ pow
*/
static BigInt bigPow10(unsigned short pow);
BigInt& toNegative();
BigInt& operator = (const BigInt& val);
BigInt& operator = (const std::string &imput);
BigInt& operator = (intMpz val);
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( const std::string &left, const BigInt &right);
friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( intMpz right, BigInt left);
friend BigInt MINIGMPSHARED_EXPORT operator - ( const std::string &right, const BigInt &left);
friend BigInt MINIGMPSHARED_EXPORT operator-(BigInt val);
friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( const std::string &left, const BigInt &right);
friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( const std::string & left, const BigInt &right);
friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator << ( BigInt left, int right);
friend BigInt MINIGMPSHARED_EXPORT operator >> ( BigInt left, int right);
friend BigInt MINIGMPSHARED_EXPORT & operator <<= ( BigInt &left, int right);
friend BigInt MINIGMPSHARED_EXPORT & operator >>= ( BigInt &left, int right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator == ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator != ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator != ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator < ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator < ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator > ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator > ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator <= ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator >= ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( intMpz left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator!(const BigInt& val);
BigInt& operator-- ();
BigInt& operator++ ();
BigInt operator-- (int);
BigInt operator++ (int);
friend BigInt MINIGMPSHARED_EXPORT operator~ (BigInt val);
friend BigInt MINIGMPSHARED_EXPORT operator| (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator| (const BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator& (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator& (const BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator^ (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator^ (const BigInt &left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, intMpz right);
};
#endif // BIGINT_H