42 #ifdef __SIZEOF_INT128__
43 #define BIG_INTEGER_WORD_BITS 128U
44 #define BIG_INTEGER_WORD_POWER 7U
45 #define BIG_INTEGER_WORD unsigned __int128
46 #define BIG_INTEGER_HALF_WORD uint64_t
47 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFFFFFFFFFULL
48 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFFFFFFFFFF0000000000000000ULL
50 #define BIG_INTEGER_WORD_BITS 64U
51 #define BIG_INTEGER_WORD_POWER 6U
52 #define BIG_INTEGER_WORD uint64_t
53 #define BIG_INTEGER_HALF_WORD uint32_t
54 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFULL
55 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFF00000000ULL
90 #ifdef __SIZEOF_INT128__
91 inline explicit operator unsigned __int128()
const {
return (
unsigned __int128)
bits[0
U]; }
93 inline explicit operator uint64_t()
const {
return (uint64_t)
bits[0
U]; }
94 inline explicit operator uint32_t()
const {
return (uint32_t)
bits[0
U]; }
152 if (left.
bits[0] > 1U) {
155 if (left.
bits[0] < 1U) {
168 result.
bits[i + 1] = (result.
bits[i] < left.
bits[i]) ? 1 : 0;
182 temp = left->
bits[++j]++;
194 result.
bits[i + 1] = (result.
bits[i] > left.
bits[i]) ? -1 : 0;
208 temp = left->
bits[++j]--;
217 pBigInt->
bits[0] += value;
218 if (temp <= pBigInt->bits[0]) {
222 temp = pBigInt->
bits[i]++;
223 if (temp <= pBigInt->bits[i]) {
232 pBigInt->
bits[0] -= value;
233 if (temp >= pBigInt->
bits[0]) {
237 temp = pBigInt->
bits[i]--;
238 if (temp >= pBigInt->
bits[i]) {
248 result.
bits[i] = a[i];
262 result.
bits[i] = left.
bits[i - rightMult];
275 left->
bits[i] = left->
bits[i - rightMult];
290 result.
bits[i - rightMult] = left.
bits[i];
302 left->
bits[i - rightMult] = left->
bits[i];
322 right = result.bits[i];
323 result.bits[i] = carry | (right << rMod);
324 carry = right >> rModComp;
343 right = left->
bits[i];
344 left->
bits[i] = carry | (right << rMod);
345 carry = right >> rModComp;
362 right = result.bits[i];
363 result.bits[i] = carry | (right >> rMod);
364 carry = right << rModComp;
383 right = left->
bits[i];
384 left->
bits[i] = carry | (right >> rMod);
385 carry = right << rModComp;
BigInteger operator~(const BigInteger &left)
Definition: big_integer.hpp:453
void bi_or_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:429
constexpr size_t BIG_INTEGER_BITS
Definition: big_integer.hpp:59
constexpr size_t BIG_INTEGER_HALF_WORD_BITS
Definition: big_integer.hpp:63
BigInteger operator--(BigInteger &a)
Definition: big_integer.hpp:494
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:229
BigInteger operator&(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:402
BigInteger operator>>(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:349
void bi_increment(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:214
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:179
#define BIG_INTEGER_WORD_POWER
Definition: big_integer.hpp:51
constexpr int BIG_INTEGER_MAX_WORD_INDEX
Definition: big_integer.hpp:65
int bi_and_1(const BigInteger &left)
Definition: big_integer.hpp:400
bool operator>=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:486
BigInteger operator|(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:419
BigInteger operator+(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:162
void bi_add_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:175
bool operator>(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:485
BigInteger bi_rshift_word(const BigInteger &left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:282
BigInteger operator^(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:436
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:134
BigInteger bi_lshift_word(const BigInteger &left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:254
int bi_compare(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:120
void bi_and_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:412
constexpr int BIG_INTEGER_WORD_SIZE
Definition: big_integer.hpp:60
BigInteger operator<<(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:309
#define BIG_INTEGER_WORD_BITS
Definition: big_integer.hpp:50
#define BIG_INTEGER_WORD
Definition: big_integer.hpp:52
void bi_lshift_word_ip(BigInteger *left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:268
bool operator==(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:482
double bi_to_double(const BigInteger &in)
Definition: big_integer.hpp:470
void bi_copy_ip(const BigInteger &in, BigInteger *out)
Definition: big_integer.hpp:113
BigInteger bi_copy(const BigInteger &in)
Definition: big_integer.hpp:104
void bi_rshift_word_ip(BigInteger *left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:296
void bi_not_ip(BigInteger *left)
Definition: big_integer.hpp:463
int bi_compare_1(const BigInteger &left)
Definition: big_integer.hpp:145
bool operator<(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:483
void bi_set_0(BigInteger *p)
Definition: big_integer.hpp:97
void bi_xor_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:446
void bi_sub_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:201
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:389
constexpr int BIG_INTEGER_HALF_WORD_SIZE
Definition: big_integer.hpp:64
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:218
BigInteger bi_load(BIG_INTEGER_WORD *a)
Definition: big_integer.hpp:244
void bi_lshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:330
bool operator<=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:484
#define BIG_INTEGER_HALF_WORD
Definition: big_integer.hpp:53
struct BigInteger BigInteger
BigInteger operator-(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:188
void bi_rshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:370
BigInteger operator++(BigInteger &a)
Definition: big_integer.hpp:488
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:1562
Definition: big_integer.hpp:67
BigInteger(const BIG_INTEGER_WORD &val)
Definition: big_integer.hpp:82
BIG_INTEGER_WORD bits[BIG_INTEGER_WORD_SIZE]
Definition: big_integer.hpp:68
BigInteger()
Definition: big_integer.hpp:70
BigInteger(const BigInteger &val)
Definition: big_integer.hpp:75