QtBigInt
Loading...
Searching...
No Matches
bigint.h
Go to the documentation of this file.
1//#
2//# Copyright (C) 2018-2021 QuasarApp.
3//# Distributed under the lgplv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8
9#ifndef BIGINT_H
10#define BIGINT_H
11#include "mini-gmp.h"
12#include <string>
13#include <vector>
14#include "minigmp_global.h"
15
21{
22 mpz_t data;
23public:
24 BigInt();
25 BigInt(const BigInt& val, int bitCount = -1);
26 BigInt(const std::string &imput, int base = 10);
27 BigInt(intMpz val);
28 BigInt(char item, unsigned int size, int base);
29
30 std::string getString(int base = 10) const;
31 ~BigInt();
32
33 BigInt& powm(const BigInt &pow, const BigInt &mod);
34 static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
35
36 BigInt& pow(uIntMpz pow);
37 BigInt& log(int base);
42 int sizeBits() const;
43 int sizeBytes() const;
44
49 int longBits() const;
50 int longBytes() const;
51
52 int sizeType() const;
53 bool isPrime(bool absalut = false) const;
54 BigInt& gcd(const BigInt &a, const BigInt &b);
55 void fromHex(const std::string& hex);
56
62 static BigInt bigPow10(unsigned short pow);
63
64 BigInt& toNegative();
65
66 BigInt& operator = (const BigInt& val);
67 BigInt& operator = (const std::string &imput);
68 BigInt& operator = (intMpz val);
69
70 friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const BigInt& right);
71 friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const std::string &right);
73
75 friend BigInt MINIGMPSHARED_EXPORT operator + ( const std::string &left, const BigInt &right);
76
78 friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const BigInt& right);
79 friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const std::string &right);
80
81 friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const BigInt& right);
83 friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const std::string &right);
84
86 friend BigInt MINIGMPSHARED_EXPORT operator - ( const std::string &right, const BigInt &left);
87
89
91
92 friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const BigInt& right);
93 friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const std::string &right);
94
95 friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const BigInt& right);
96 friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const std::string &right);
99 friend BigInt MINIGMPSHARED_EXPORT operator / ( const std::string &left, const BigInt &right);
100
101 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, intMpz right);
102 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const std::string &right);
103 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const BigInt& right);
104
105 friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const BigInt& right);
106 friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const std::string &right);
108
110
111 friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, const BigInt& right);
112 friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, intMpz right);
113 friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, const std::string &right);
114
115 friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const BigInt& right);
116 friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const std::string &right);
118
120 friend BigInt MINIGMPSHARED_EXPORT operator % ( const std::string & left, const BigInt &right);
121
122 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, intMpz right);
123 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const std::string &right);
124
125 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const BigInt& right);
126
127 friend BigInt MINIGMPSHARED_EXPORT operator << ( BigInt left, int right);
128 friend BigInt MINIGMPSHARED_EXPORT operator >> ( BigInt left, int right);
129
130 friend BigInt MINIGMPSHARED_EXPORT & operator <<= ( BigInt &left, int right);
131 friend BigInt MINIGMPSHARED_EXPORT & operator >>= ( BigInt &left, int right);
132
133 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const BigInt& right);
134 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, intMpz right);
135 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
136 friend bool MINIGMPSHARED_EXPORT operator == ( const std::string& left, const BigInt& right);
137 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
138 friend bool MINIGMPSHARED_EXPORT operator == ( intMpz left, const std::string& right);
139
140 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const BigInt& right);
141 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, intMpz right);
142 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& str);
143 friend bool MINIGMPSHARED_EXPORT operator != ( const std::string& left, const BigInt& right);
144 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& right);
145 friend bool MINIGMPSHARED_EXPORT operator != ( intMpz left, const std::string& right);
146
147 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const BigInt& right);
148 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, intMpz right);
149 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& str);
150 friend bool MINIGMPSHARED_EXPORT operator < ( const std::string& left, const BigInt& right);
151 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& right);
152 friend bool MINIGMPSHARED_EXPORT operator < ( intMpz left, const std::string& right);
153
154 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const BigInt& right);
155 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, intMpz right);
156 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& str);
157 friend bool MINIGMPSHARED_EXPORT operator > ( const std::string& left, const BigInt& right);
158 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& right);
159 friend bool MINIGMPSHARED_EXPORT operator > ( intMpz left, const std::string& right);
160
161 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const BigInt& right);
162 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, intMpz right);
163 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& str);
164 friend bool MINIGMPSHARED_EXPORT operator <= ( const std::string& left, const BigInt& right);
165 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& right);
166 friend bool MINIGMPSHARED_EXPORT operator <= ( intMpz left, const std::string& right);
167
168 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const BigInt& right);
169 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, intMpz right);
170 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& str);
171 friend bool MINIGMPSHARED_EXPORT operator >= ( const std::string& left, const BigInt& right);
172 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& right);
173 friend bool MINIGMPSHARED_EXPORT operator >= ( intMpz left, const std::string& right);
174
175 friend bool MINIGMPSHARED_EXPORT operator!(const BigInt& val);
176
177 BigInt& operator-- ();
178 BigInt& operator++ ();
179
180 BigInt operator-- (int);
181 BigInt operator++ (int);
182
183
185
186 friend BigInt MINIGMPSHARED_EXPORT operator| (BigInt left, const BigInt& right);
187 friend BigInt MINIGMPSHARED_EXPORT operator| (const BigInt &left, intMpz right);
188
189 friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, const BigInt& right);
190 friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, intMpz right);
191
192 friend BigInt MINIGMPSHARED_EXPORT operator& (BigInt left, const BigInt& right);
193 friend BigInt MINIGMPSHARED_EXPORT operator& (const BigInt &left, intMpz right);
194
195 friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, const BigInt& right);
196 friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, intMpz right);
197
198 friend BigInt MINIGMPSHARED_EXPORT operator^ (BigInt left, const BigInt& right);
199 friend BigInt MINIGMPSHARED_EXPORT operator^ (const BigInt &left, intMpz right);
200
201 friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, const BigInt& right);
202 friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, intMpz right);
203
204};
205
206#endif // BIGINT_H
BigInt operator*(BigInt left, const BigInt &right)
Definition: bigint.cpp:272
bool operator==(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:494
BigInt & operator+=(BigInt &left, intMpz right)
Definition: bigint.cpp:155
BigInt & operator<<=(BigInt &left, int right)
Definition: bigint.cpp:414
bool operator<=(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:574
BigInt & operator&=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:460
BigInt operator%(BigInt left, const BigInt &right)
Definition: bigint.cpp:317
BigInt operator~(BigInt left)
Definition: bigint.cpp:427
BigInt operator<<(BigInt left, int right)
Definition: bigint.cpp:390
BigInt operator+(BigInt left, intMpz right)
Definition: bigint.cpp:129
bool operator>(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:554
BigInt & operator|=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:441
bool operator<(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:534
BigInt & operator^=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:478
BigInt operator|(BigInt left, const BigInt &right)
Definition: bigint.cpp:432
BigInt & operator/=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:253
BigInt & operator*=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:298
BigInt & operator>>=(BigInt &left, int right)
Definition: bigint.cpp:402
BigInt & operator%=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:339
bool operator>=(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:594
BigInt operator/(BigInt left, const BigInt &right)
Definition: bigint.cpp:227
BigInt operator>>(BigInt left, int right)
Definition: bigint.cpp:378
BigInt operator^(BigInt left, const BigInt &right)
Definition: bigint.cpp:469
bool operator!=(const BigInt &left, const BigInt &right)
Definition: bigint.cpp:514
BigInt & operator-=(BigInt &left, const BigInt &right)
Definition: bigint.cpp:208
BigInt operator&(BigInt left, const BigInt &right)
Definition: bigint.cpp:450
BigInt operator-(BigInt left, const BigInt &right)
Definition: bigint.cpp:174
bool operator!(const BigInt &val)
Definition: bigint.cpp:490
The BigInt class - c++ minigmp wrapper.
Definition: bigint.h:21
BigInt & log(int base)
unsigned long long uIntMpz
Definition: mini-gmp.h:58
__mpz_struct mpz_t[1]
Definition: mini-gmp.h:78
long long intMpz
Definition: mini-gmp.h:59
#define MINIGMPSHARED_EXPORT