45 #ifdef __SIZEOF_INT128__
46 #define BIG_INTEGER_WORD_BITS 128U
47 #define BIG_INTEGER_WORD_POWER 7U
48 #define BIG_INTEGER_WORD unsigned __int128
49 #define BIG_INTEGER_HALF_WORD uint64_t
50 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFFFFFFFFFULL
51 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFFFFFFFFFF0000000000000000ULL
53 #define BIG_INTEGER_WORD_BITS 64U
54 #define BIG_INTEGER_WORD_POWER 6U
55 #define BIG_INTEGER_WORD uint64_t
56 #define BIG_INTEGER_HALF_WORD uint32_t
57 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFULL
58 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFF00000000ULL
95 #ifdef __SIZEOF_INT128__
96 inline explicit operator unsigned __int128()
const {
return (
unsigned __int128)
bits[0
U]; }
98 inline explicit operator uint64_t()
const {
return (uint64_t)
bits[0
U]; }
99 inline explicit operator uint32_t()
const {
return (uint32_t)
bits[0
U]; }
159 if (left.
bits[0] > 1U) {
163 if (left.
bits[0] < 1U) {
176 result.
bits[i + 1] = (result.
bits[i] < left.
bits[i]) ? 1 : 0;
189 temp = left->
bits[++j]++;
201 result.
bits[i + 1] = (result.
bits[i] > left.
bits[i]) ? -1 : 0;
214 temp = left->
bits[++j]--;
223 pBigInt->
bits[0] += value;
225 if (temp <= pBigInt->bits[0]) {
230 temp = pBigInt->
bits[i]++;
231 if (temp <= pBigInt->bits[i]) {
240 pBigInt->
bits[0] -= value;
242 if (temp >= pBigInt->
bits[0]) {
247 temp = pBigInt->
bits[i]--;
248 if (temp >= pBigInt->
bits[i]) {
258 result.
bits[i] = a[i];
272 result.
bits[i] = left.
bits[i - rightMult];
287 left->
bits[i] = left->
bits[i - rightMult];
302 result.
bits[i - rightMult] = left.
bits[i];
315 left->
bits[i - rightMult] = left->
bits[i];
336 right = result.bits[i];
337 result.bits[i] = carry | (right << rMod);
338 carry = right >> rModComp;
358 right = left->
bits[i];
359 left->
bits[i] = carry | (right << rMod);
360 carry = right >> rModComp;
378 right = result.bits[i];
379 result.bits[i] = carry | (right >> rMod);
380 carry = right << rModComp;
400 right = left->
bits[i];
401 left->
bits[i] = carry | (right >> rMod);
402 carry = right << rModComp;
BigInteger operator~(const BigInteger &left)
Definition: big_integer.hpp:467
void bi_or_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:444
constexpr size_t BIG_INTEGER_BITS
Definition: big_integer.hpp:62
constexpr size_t BIG_INTEGER_HALF_WORD_BITS
Definition: big_integer.hpp:66
BigInteger operator--(BigInteger &a)
Definition: big_integer.hpp:506
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:237
BigInteger operator&(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:419
BigInteger operator>>(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:364
void bi_increment(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:220
void bi_div_mod_small(const BigInteger &left, BIG_INTEGER_HALF_WORD right, BigInteger *quotient, BIG_INTEGER_HALF_WORD *rmndr)
"Schoolbook division" (on half words) Complexity - O(x^2)
Definition: big_integer.cpp:182
#define BIG_INTEGER_WORD_POWER
Definition: big_integer.hpp:54
constexpr int BIG_INTEGER_MAX_WORD_INDEX
Definition: big_integer.hpp:68
int bi_and_1(const BigInteger &left)
Definition: big_integer.hpp:417
bool operator>=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:498
BigInteger operator|(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:435
BigInteger operator+(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:170
void bi_add_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:182
bool operator>(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:497
BigInteger bi_rshift_word(const BigInteger &left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:294
BigInteger operator^(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:451
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:140
BigInteger bi_lshift_word(const BigInteger &left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:264
int bi_compare(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:125
void bi_and_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:428
constexpr int BIG_INTEGER_WORD_SIZE
Definition: big_integer.hpp:63
BigInteger operator<<(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:322
#define BIG_INTEGER_WORD_BITS
Definition: big_integer.hpp:53
#define BIG_INTEGER_WORD
Definition: big_integer.hpp:55
void bi_lshift_word_ip(BigInteger *left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:278
bool operator==(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:494
double bi_to_double(const BigInteger &in)
Definition: big_integer.hpp:483
void bi_copy_ip(const BigInteger &in, BigInteger *out)
Definition: big_integer.hpp:118
BigInteger bi_copy(const BigInteger &in)
Definition: big_integer.hpp:109
void bi_rshift_word_ip(BigInteger *left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:308
void bi_not_ip(BigInteger *left)
Definition: big_integer.hpp:476
int bi_compare_1(const BigInteger &left)
Definition: big_integer.hpp:151
bool operator<(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:495
void bi_set_0(BigInteger *p)
Definition: big_integer.hpp:102
void bi_xor_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:460
void bi_sub_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:207
BigInteger operator*(const BigInteger &left, BIG_INTEGER_HALF_WORD right)
"Schoolbook multiplication" (on half words) Complexity - O(x^2)
Definition: big_integer.cpp:39
int bi_log2(const BigInteger &n)
Definition: big_integer.hpp:406
constexpr int BIG_INTEGER_HALF_WORD_SIZE
Definition: big_integer.hpp:67
void bi_div_mod(const BigInteger &left, const BigInteger &right, BigInteger *quotient, BigInteger *rmndr)
Adapted from Qrack! (The fundamental algorithm was discovered before.) Complexity - O(log)
Definition: big_integer.cpp:221
BigInteger bi_load(BIG_INTEGER_WORD *a)
Definition: big_integer.hpp:254
void bi_lshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:344
bool operator<=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:496
#define BIG_INTEGER_HALF_WORD
Definition: big_integer.hpp:56
struct BigInteger BigInteger
BigInteger operator-(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:195
void bi_rshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:386
BigInteger operator++(BigInteger &a)
Definition: big_integer.hpp:500
half pow(half x, half y)
Power function.
Definition: half.hpp:3738
MICROSOFT_QUANTUM_DECL void U(_In_ uintq sid, _In_ uintq q, _In_ double theta, _In_ double phi, _In_ double lambda)
(External API) 3-parameter unitary gate
Definition: pinvoke_api.cpp:1713
Definition: big_integer.hpp:70
BigInteger(const BIG_INTEGER_WORD &val)
Definition: big_integer.hpp:87
BIG_INTEGER_WORD bits[BIG_INTEGER_WORD_SIZE]
Definition: big_integer.hpp:71
BigInteger()
Definition: big_integer.hpp:73
BigInteger(const BigInteger &val)
Definition: big_integer.hpp:80