21 template<
unsigned int BITS>
25 static_assert(BITS / 32 > 0 && BITS % 32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
26 static constexpr
int WIDTH = BITS / 32;
32 for (
int i = 0; i <
WIDTH; i++)
38 for (
int i = 0; i <
WIDTH; i++)
44 for (
int i = 0; i <
WIDTH; i++)
51 pn[0] = (
unsigned int)b;
52 pn[1] = (
unsigned int)(b >> 32);
53 for (
int i = 2; i <
WIDTH; i++)
62 for (
int i = 0; i <
WIDTH; i++)
70 for (
int i = 0; i <
WIDTH; i++)
80 pn[0] = (
unsigned int)b;
81 pn[1] = (
unsigned int)(b >> 32);
82 for (
int i = 2; i <
WIDTH; i++)
89 for (
int i = 0; i <
WIDTH; i++)
96 for (
int i = 0; i <
WIDTH; i++)
103 for (
int i = 0; i <
WIDTH; i++)
110 pn[0] ^= (
unsigned int)b;
111 pn[1] ^= (
unsigned int)(b >> 32);
117 pn[0] |= (
unsigned int)b;
118 pn[1] |= (
unsigned int)(b >> 32);
128 for (
int i = 0; i <
WIDTH; i++)
130 uint64_t n = carry +
pn[i] + b.
pn[i];
131 pn[i] = n & 0xffffffff;
167 while (i <
WIDTH && ++
pn[i] == 0)
234 static_assert(
WIDTH >= 2,
"Assertion WIDTH >= 2 failed (WIDTH = BITS / 32). BITS is a template parameter.");
235 return pn[0] | (uint64_t)
pn[1] << 32;
Definition: arith_uint256.h:23
base_uint & operator=(const base_uint &b)
Definition: arith_uint256.h:42
base_uint operator~() const
Definition: arith_uint256.h:59
uint32_t pn[WIDTH]
Definition: arith_uint256.h:27
base_uint & operator=(uint64_t b)
Definition: arith_uint256.h:78
int CompareTo(const base_uint &b) const
base_uint & operator+=(uint64_t b64)
Definition: arith_uint256.h:143
base_uint operator--(int)
Definition: arith_uint256.h:189
unsigned int size() const
Definition: arith_uint256.h:221
base_uint(uint64_t b)
Definition: arith_uint256.h:49
base_uint & operator--()
Definition: arith_uint256.h:180
base_uint & operator>>=(unsigned int shift)
friend bool operator!=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:211
base_uint & operator^=(uint64_t b)
Definition: arith_uint256.h:108
base_uint & operator++()
Definition: arith_uint256.h:163
base_uint & operator<<=(unsigned int shift)
friend base_uint operator-(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:201
base_uint(const base_uint &b)
Definition: arith_uint256.h:36
friend base_uint operator*(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:202
static constexpr int WIDTH
Definition: arith_uint256.h:26
base_uint & operator&=(const base_uint &b)
Definition: arith_uint256.h:94
friend base_uint operator<<(const base_uint &a, int shift)
Definition: arith_uint256.h:208
base_uint & operator/=(const base_uint &b)
friend base_uint operator&(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:205
friend bool operator<(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:213
base_uint & operator-=(const base_uint &b)
Definition: arith_uint256.h:137
base_uint & operator+=(const base_uint &b)
Definition: arith_uint256.h:125
base_uint & operator*=(const base_uint &b)
friend bool operator==(const base_uint &a, uint64_t b)
Definition: arith_uint256.h:216
base_uint operator-() const
Definition: arith_uint256.h:67
friend base_uint operator>>(const base_uint &a, int shift)
Definition: arith_uint256.h:207
friend bool operator>=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:214
friend base_uint operator|(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:204
bool EqualTo(uint64_t b) const
friend base_uint operator*(const base_uint &a, uint32_t b)
Definition: arith_uint256.h:209
friend bool operator==(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:210
base_uint()
Definition: arith_uint256.h:30
base_uint & operator|=(const base_uint &b)
Definition: arith_uint256.h:101
base_uint & operator-=(uint64_t b64)
Definition: arith_uint256.h:151
friend bool operator!=(const base_uint &a, uint64_t b)
Definition: arith_uint256.h:217
friend base_uint operator/(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:203
friend base_uint operator^(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:206
friend bool operator>(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:212
friend bool operator<=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:215
base_uint & operator|=(uint64_t b)
Definition: arith_uint256.h:115
base_uint operator++(int)
Definition: arith_uint256.h:172
base_uint & operator^=(const base_uint &b)
Definition: arith_uint256.h:87
uint64_t GetLow64() const
Definition: arith_uint256.h:232
base_uint & operator*=(uint32_t b32)
friend base_uint operator+(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:200
unsigned int bits() const
Definition: arith_uint256.h:15
uint_error(const std::string &str)
Definition: arith_uint256.h:17