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);
45 int sizeBits() const;
46 int sizeBytes() const;
47
55 int longBits() const;
56 int longBytes() const;
57
58 int sizeType() const;
59 bool isPrime(bool absalut = false) const;
60 BigInt& gcd(const BigInt &a, const BigInt &b);
61 void fromHex(const std::string& hex);
62
72 static BigInt bigPow10(unsigned short pow);
73
74 BigInt& toNegative();
75
76 BigInt& operator = (const BigInt& val);
77 BigInt& operator = (const std::string &imput);
78 BigInt& operator = (intMpz val);
79
80 friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const BigInt& right);
81 friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const std::string &right);
83
85 friend BigInt MINIGMPSHARED_EXPORT operator + ( const std::string &left, const BigInt &right);
86
88 friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const BigInt& right);
89 friend BigInt MINIGMPSHARED_EXPORT & operator += ( BigInt &left, const std::string &right);
90
91 friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const BigInt& right);
93 friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const std::string &right);
94
96 friend BigInt MINIGMPSHARED_EXPORT operator - ( const std::string &right, const BigInt &left);
97
99
100 friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, intMpz right);
101
102 friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const BigInt& right);
103 friend BigInt MINIGMPSHARED_EXPORT & operator -= ( BigInt &left, const std::string &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);
109 friend BigInt MINIGMPSHARED_EXPORT operator / ( const std::string &left, const BigInt &right);
110
111 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, intMpz right);
112 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const std::string &right);
113 friend BigInt MINIGMPSHARED_EXPORT & operator /= ( BigInt &left, const BigInt& 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
121 friend BigInt MINIGMPSHARED_EXPORT & operator *= ( BigInt &left, const BigInt& right);
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 friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const std::string &right);
128
130 friend BigInt MINIGMPSHARED_EXPORT operator % ( const std::string & left, const BigInt &right);
131
132 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, intMpz right);
133 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const std::string &right);
134
135 friend BigInt MINIGMPSHARED_EXPORT & operator %= ( BigInt &left, const BigInt& right);
136
137 friend BigInt MINIGMPSHARED_EXPORT operator << ( BigInt left, int right);
138 friend BigInt MINIGMPSHARED_EXPORT operator >> ( BigInt left, int right);
139
140 friend BigInt MINIGMPSHARED_EXPORT & operator <<= ( BigInt &left, int right);
141 friend BigInt MINIGMPSHARED_EXPORT & operator >>= ( BigInt &left, int right);
142
143 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const BigInt& right);
144 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, intMpz right);
145 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
146 friend bool MINIGMPSHARED_EXPORT operator == ( const std::string& left, const BigInt& right);
147 friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
148 friend bool MINIGMPSHARED_EXPORT operator == ( intMpz left, const std::string& right);
149
150 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const BigInt& right);
151 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, intMpz right);
152 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& str);
153 friend bool MINIGMPSHARED_EXPORT operator != ( const std::string& left, const BigInt& right);
154 friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& right);
155 friend bool MINIGMPSHARED_EXPORT operator != ( intMpz left, const std::string& right);
156
157 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const BigInt& right);
158 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, intMpz right);
159 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& str);
160 friend bool MINIGMPSHARED_EXPORT operator < ( const std::string& left, const BigInt& right);
161 friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& right);
162 friend bool MINIGMPSHARED_EXPORT operator < ( intMpz left, const std::string& right);
163
164 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const BigInt& right);
165 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, intMpz right);
166 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& str);
167 friend bool MINIGMPSHARED_EXPORT operator > ( const std::string& left, const BigInt& right);
168 friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& right);
169 friend bool MINIGMPSHARED_EXPORT operator > ( intMpz left, const std::string& right);
170
171 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const BigInt& right);
172 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, intMpz right);
173 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& str);
174 friend bool MINIGMPSHARED_EXPORT operator <= ( const std::string& left, const BigInt& right);
175 friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& right);
176 friend bool MINIGMPSHARED_EXPORT operator <= ( intMpz left, const std::string& right);
177
178 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const BigInt& right);
179 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, intMpz right);
180 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& str);
181 friend bool MINIGMPSHARED_EXPORT operator >= ( const std::string& left, const BigInt& right);
182 friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& right);
183 friend bool MINIGMPSHARED_EXPORT operator >= ( intMpz left, const std::string& right);
184
185 friend bool MINIGMPSHARED_EXPORT operator!(const BigInt& val);
186
187 BigInt& operator-- ();
188 BigInt& operator++ ();
189
190 BigInt operator-- (int);
191 BigInt operator++ (int);
192
193
195
196 friend BigInt MINIGMPSHARED_EXPORT operator| (BigInt left, const BigInt& right);
197 friend BigInt MINIGMPSHARED_EXPORT operator| (const BigInt &left, intMpz right);
198
199 friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, const BigInt& right);
200 friend BigInt MINIGMPSHARED_EXPORT & operator|= (BigInt &left, intMpz right);
201
202 friend BigInt MINIGMPSHARED_EXPORT operator& (BigInt left, const BigInt& right);
203 friend BigInt MINIGMPSHARED_EXPORT operator& (const BigInt &left, intMpz right);
204
205 friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, const BigInt& right);
206 friend BigInt MINIGMPSHARED_EXPORT & operator&= (BigInt &left, intMpz right);
207
208 friend BigInt MINIGMPSHARED_EXPORT operator^ (BigInt left, const BigInt& right);
209 friend BigInt MINIGMPSHARED_EXPORT operator^ (const BigInt &left, intMpz right);
210
211 friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, const BigInt& right);
212 friend BigInt MINIGMPSHARED_EXPORT & operator^= (BigInt &left, intMpz right);
213
214};
215
216#endif // BIGINT_H
BigInt operator*(BigInt left, const BigInt &right)
Definition bigint.cpp:275
bool operator==(const BigInt &left, const BigInt &right)
Definition bigint.cpp:497
BigInt & operator+=(BigInt &left, intMpz right)
Definition bigint.cpp:158
BigInt & operator<<=(BigInt &left, int right)
Definition bigint.cpp:417
bool operator<=(const BigInt &left, const BigInt &right)
Definition bigint.cpp:577
BigInt & operator&=(BigInt &left, const BigInt &right)
Definition bigint.cpp:463
BigInt operator%(BigInt left, const BigInt &right)
Definition bigint.cpp:320
BigInt operator~(BigInt left)
Definition bigint.cpp:430
BigInt operator<<(BigInt left, int right)
Definition bigint.cpp:393
BigInt operator+(BigInt left, intMpz right)
Definition bigint.cpp:132
bool operator>(const BigInt &left, const BigInt &right)
Definition bigint.cpp:557
BigInt & operator|=(BigInt &left, const BigInt &right)
Definition bigint.cpp:444
bool operator<(const BigInt &left, const BigInt &right)
Definition bigint.cpp:537
BigInt & operator^=(BigInt &left, const BigInt &right)
Definition bigint.cpp:481
BigInt operator|(BigInt left, const BigInt &right)
Definition bigint.cpp:435
BigInt & operator/=(BigInt &left, const BigInt &right)
Definition bigint.cpp:256
BigInt & operator*=(BigInt &left, const BigInt &right)
Definition bigint.cpp:301
BigInt & operator>>=(BigInt &left, int right)
Definition bigint.cpp:405
BigInt & operator%=(BigInt &left, const BigInt &right)
Definition bigint.cpp:342
bool operator>=(const BigInt &left, const BigInt &right)
Definition bigint.cpp:597
BigInt operator/(BigInt left, const BigInt &right)
Definition bigint.cpp:230
BigInt operator>>(BigInt left, int right)
Definition bigint.cpp:381
BigInt operator^(BigInt left, const BigInt &right)
Definition bigint.cpp:472
bool operator!=(const BigInt &left, const BigInt &right)
Definition bigint.cpp:517
BigInt & operator-=(BigInt &left, const BigInt &right)
Definition bigint.cpp:211
BigInt operator&(BigInt left, const BigInt &right)
Definition bigint.cpp:453
BigInt operator-(BigInt left, const BigInt &right)
Definition bigint.cpp:177
bool operator!(const BigInt &val)
Definition bigint.cpp:493
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