12 template <
unsigned int BITS>
15 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
20 template <
unsigned int BITS>
24 for (
int i = 0; i < WIDTH; i++)
28 for (
int i = 0; i < WIDTH; i++) {
29 if (i + k + 1 < WIDTH && shift != 0)
30 pn[i +
k + 1] |= (a.pn[i] >> (32 - shift));
32 pn[i +
k] |= (a.pn[i] << shift);
37 template <
unsigned int BITS>
41 for (
int i = 0; i < WIDTH; i++)
45 for (
int i = 0; i < WIDTH; i++) {
46 if (i -
k - 1 >= 0 && shift != 0)
47 pn[i -
k - 1] |= (a.
pn[i] << (32 - shift));
49 pn[i -
k] |= (a.
pn[i] >> shift);
54 template <
unsigned int BITS>
58 for (
int i = 0; i < WIDTH; i++) {
59 uint64_t n = carry + (uint64_t)b32 * pn[i];
60 pn[i] = n & 0xffffffff;
66 template <
unsigned int BITS>
70 for (
int j = 0; j < WIDTH; j++) {
72 for (
int i = 0; i + j < WIDTH; i++) {
73 uint64_t n = carry + a.
pn[i + j] + (uint64_t)pn[j] * b.
pn[i];
74 a.
pn[i + j] = n & 0xffffffff;
82 template <
unsigned int BITS>
88 int num_bits = num.
bits();
89 int div_bits = div.
bits();
92 if (div_bits > num_bits)
94 int shift = num_bits - div_bits;
99 pn[shift / 32] |= (1U << (shift & 31));
108 template <
unsigned int BITS>
111 for (
int i = WIDTH - 1; i >= 0; i--) {
120 template <
unsigned int BITS>
123 for (
int i = WIDTH - 1; i >= 2; i--) {
127 if (pn[1] != (b >> 32))
129 if (pn[0] != (b & 0xfffffffful))
134 template <
unsigned int BITS>
139 for (
int i = 0; i < WIDTH; i++) {
141 fact *= 4294967296.0;
146 template <
unsigned int BITS>
150 for (
int x = 0; x < this->WIDTH; ++x) {
156 template <
unsigned int BITS>
161 for (
int x = 0; x < this->WIDTH; ++x) {
166 template <
unsigned int BITS>
172 template <
unsigned int BITS>
178 template <
unsigned int BITS>
181 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
183 for (
int nbits = 31; nbits > 0; nbits--) {
184 if (pn[pos] & 1U << nbits)
185 return 32 * pos + nbits + 1;
200 int nSize = nCompact >> 24;
201 uint32_t nWord = nCompact & 0x007fffff;
203 nWord >>= 8 * (3 - nSize);
207 *
this <<= 8 * (nSize - 3);
210 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
212 *pfOverflow = nWord != 0 && ((nSize > 34) ||
213 (nWord > 0xff && nSize > 33) ||
214 (nWord > 0xffff && nSize > 32));
220 int nSize = (
bits() + 7) / 8;
221 uint32_t nCompact = 0;
230 if (nCompact & 0x00800000) {
234 assert((nCompact & ~0x007fffffU) == 0);
236 nCompact |= nSize << 24;
237 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
244 for(
int x=0; x<a.
WIDTH; ++x)
251 for(
int x=0; x<b.
WIDTH; ++x)
arith_uint256 UintToArith256(const uint256 &a)
uint256 ArithToUint256(const arith_uint256 &a)
256-bit unsigned big integer.
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
uint32_t GetCompact(bool fNegative=false) const
Template base class for fixed-sized opaque blobs.
void SetHex(const char *psz)
constexpr unsigned char * begin()
std::string GetHex() const
Template base class for unsigned big integers.
int CompareTo(const base_uint &b) const
base_uint & operator>>=(unsigned int shift)
static constexpr int WIDTH
base_uint & operator*=(uint32_t b32)
bool EqualTo(uint64_t b) const
base_uint & operator<<=(unsigned int shift)
std::string ToString() const
base_uint & operator/=(const base_uint &b)
uint64_t GetLow64() const
void SetHex(const char *psz)
std::string GetHex() const
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.
static uint32_t ReadLE32(const unsigned char *ptr)
static void WriteLE32(unsigned char *ptr, uint32_t x)