46 #if defined(__SIZEOF_INT128__) && defined(ENABLE_CPP_INT)
47 #define BIG_INTEGER_WORD_BITS 128U
48 #define BIG_INTEGER_WORD_POWER 7U
49 #define BIG_INTEGER_WORD unsigned __int128
50 #define BIG_INTEGER_HALF_WORD uint64_t
51 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFFFFFFFFFULL
52 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFFFFFFFFFF0000000000000000ULL
54 #define BIG_INTEGER_WORD_BITS 64U
55 #define BIG_INTEGER_WORD_POWER 6U
56 #define BIG_INTEGER_WORD uint64_t
57 #define BIG_INTEGER_HALF_WORD uint32_t
58 #define BIG_INTEGER_HALF_WORD_MASK 0xFFFFFFFFULL
59 #define BIG_INTEGER_HALF_WORD_MASK_NOT 0xFFFFFFFF00000000ULL
96 #ifdef __SIZEOF_INT128__
97 inline explicit operator unsigned __int128()
const {
return (
unsigned __int128)
bits[0
U]; }
99 inline explicit operator uint64_t()
const {
return (uint64_t)
bits[0
U]; }
100 inline explicit operator uint32_t()
const {
return (uint32_t)
bits[0
U]; }
160 if (left.
bits[0] > 1U) {
164 if (left.
bits[0] < 1U) {
177 result.
bits[i + 1] = (result.
bits[i] < left.
bits[i]) ? 1 : 0;
190 temp = left->
bits[++j]++;
202 result.
bits[i + 1] = (result.
bits[i] > left.
bits[i]) ? -1 : 0;
215 temp = left->
bits[++j]--;
224 pBigInt->
bits[0] += value;
226 if (temp <= pBigInt->bits[0]) {
231 temp = pBigInt->
bits[i]++;
232 if (temp <= pBigInt->bits[i]) {
241 pBigInt->
bits[0] -= value;
243 if (temp >= pBigInt->
bits[0]) {
248 temp = pBigInt->
bits[i]--;
249 if (temp >= pBigInt->
bits[i]) {
259 result.
bits[i] = a[i];
273 result.
bits[i] = left.
bits[i - rightMult];
288 left->
bits[i] = left->
bits[i - rightMult];
303 result.
bits[i - rightMult] = left.
bits[i];
316 left->
bits[i - rightMult] = left->
bits[i];
337 right = result.bits[i];
338 result.bits[i] = carry | (right << rMod);
339 carry = right >> rModComp;
359 right = left->
bits[i];
360 left->
bits[i] = carry | (right << rMod);
361 carry = right >> rModComp;
379 right = result.bits[i];
380 result.bits[i] = carry | (right >> rMod);
381 carry = right << rModComp;
401 right = left->
bits[i];
402 left->
bits[i] = carry | (right >> rMod);
403 carry = right << rModComp;
556 size_t word =
static_cast<size_t>(bi.bits[i]);
557 word = (~word) + (word << 21);
559 word += (word << 3) + (word << 8);
561 word += (word << 2) + (word << 4);
BigInteger operator~(const BigInteger &left)
Definition: big_integer.hpp:468
void bi_or_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:445
BigInteger operator/(const BigInteger &left, BIG_INTEGER_HALF_WORD right)
Definition: big_integer.cpp:328
constexpr size_t BIG_INTEGER_BITS
Definition: big_integer.hpp:63
constexpr size_t BIG_INTEGER_HALF_WORD_BITS
Definition: big_integer.hpp:67
BigInteger operator--(BigInteger &a)
Definition: big_integer.hpp:508
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:238
BigInteger operator&(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:420
BigInteger operator>>(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:365
void bi_increment(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:221
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:184
#define BIG_INTEGER_WORD_POWER
Definition: big_integer.hpp:55
constexpr int BIG_INTEGER_MAX_WORD_INDEX
Definition: big_integer.hpp:69
int bi_and_1(const BigInteger &left)
Definition: big_integer.hpp:418
bool operator>=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:499
BigInteger operator|(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:436
BigInteger operator+(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:171
void bi_add_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:183
bool operator>(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:498
BigInteger bi_rshift_word(const BigInteger &left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:295
BigInteger operator^(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:452
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:141
bool operator!=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:500
BigInteger bi_lshift_word(const BigInteger &left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:265
int bi_compare(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:126
BIG_INTEGER_HALF_WORD operator%(const BigInteger &left, BIG_INTEGER_HALF_WORD right)
Definition: big_integer.cpp:337
void bi_and_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:429
constexpr int BIG_INTEGER_WORD_SIZE
Definition: big_integer.hpp:64
BigInteger operator<<(const BigInteger &left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:323
#define BIG_INTEGER_WORD_BITS
Definition: big_integer.hpp:54
#define BIG_INTEGER_WORD
Definition: big_integer.hpp:56
void bi_lshift_word_ip(BigInteger *left, BIG_INTEGER_WORD rightMult)
Definition: big_integer.hpp:279
bool operator==(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:495
double bi_to_double(const BigInteger &in)
Definition: big_integer.hpp:484
void bi_copy_ip(const BigInteger &in, BigInteger *out)
Definition: big_integer.hpp:119
BigInteger bi_copy(const BigInteger &in)
Definition: big_integer.hpp:110
void bi_rshift_word_ip(BigInteger *left, const BIG_INTEGER_WORD &rightMult)
Definition: big_integer.hpp:309
void bi_not_ip(BigInteger *left)
Definition: big_integer.hpp:477
int bi_compare_1(const BigInteger &left)
Definition: big_integer.hpp:152
bool operator<(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:496
void bi_set_0(BigInteger *p)
Definition: big_integer.hpp:103
void bi_xor_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:461
void bi_sub_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:208
BigInteger operator*(const BigInteger &left, BIG_INTEGER_HALF_WORD right)
"Schoolbook multiplication" (on half words) Complexity - O(x^2)
Definition: big_integer.cpp:41
int bi_log2(const BigInteger &n)
Definition: big_integer.hpp:407
constexpr int BIG_INTEGER_HALF_WORD_SIZE
Definition: big_integer.hpp:68
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:227
BigInteger bi_load(BIG_INTEGER_WORD *a)
Definition: big_integer.hpp:255
void bi_lshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:345
bool operator<=(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:497
#define BIG_INTEGER_HALF_WORD
Definition: big_integer.hpp:57
struct BigInteger BigInteger
BigInteger operator-(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:196
void bi_rshift_ip(BigInteger *left, BIG_INTEGER_WORD right)
Definition: big_integer.hpp:387
BigInteger operator++(BigInteger &a)
Definition: big_integer.hpp:502
half pow(half x, half y)
Power function.
Definition: half.hpp:3721
Extensions to the C++ standard library.
Definition: big_integer.hpp:576
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:1728
MICROSOFT_QUANTUM_DECL void seed(_In_ uintq sid, _In_ uintq s)
(External API) Set RNG seed for simulator ID
Definition: pinvoke_api.cpp:1063
Definition: big_integer.hpp:548
size_t operator()(const BigInteger &bi) const noexcept
Definition: big_integer.hpp:549
Definition: big_integer.hpp:71
BigInteger(const BIG_INTEGER_WORD &val)
Definition: big_integer.hpp:88
BIG_INTEGER_WORD bits[BIG_INTEGER_WORD_SIZE]
Definition: big_integer.hpp:72
BigInteger()
Definition: big_integer.hpp:74
BigInteger(const BigInteger &val)
Definition: big_integer.hpp:81
size_t operator()(const BigInteger &bi) const noexcept
Definition: big_integer.hpp:578