15 template <
unsigned int BITS>
18 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
23 template <
unsigned int BITS>
27 for (
int i = 0; i < WIDTH; i++)
31 for (
int i = 0; i < WIDTH; i++) {
32 if (i + k + 1 < WIDTH && shift != 0)
33 pn[i + k + 1] |= (a.
pn[i] >> (32 - shift));
35 pn[i + k] |= (a.
pn[i] << shift);
40 template <
unsigned int BITS>
44 for (
int i = 0; i < WIDTH; i++)
48 for (
int i = 0; i < WIDTH; i++) {
49 if (i - k - 1 >= 0 && shift != 0)
50 pn[i - k - 1] |= (a.
pn[i] << (32 - shift));
52 pn[i - k] |= (a.
pn[i] >> shift);
57 template <
unsigned int BITS>
61 for (
int i = 0; i < WIDTH; i++) {
62 uint64_t n = carry + (uint64_t)b32 * pn[i];
63 pn[i] = n & 0xffffffff;
69 template <
unsigned int BITS>
74 for (
int j = 0; j < WIDTH; j++) {
76 for (
int i = 0; i + j < WIDTH; i++) {
77 uint64_t n = carry + pn[i + j] + (uint64_t)a.
pn[j] * b.
pn[i];
78 pn[i + j] = n & 0xffffffff;
85 template <
unsigned int BITS>
91 int num_bits = num.
bits();
92 int div_bits = div.
bits();
95 if (div_bits > num_bits)
97 int shift = num_bits - div_bits;
102 pn[shift / 32] |= (1 << (shift & 31));
111 template <
unsigned int BITS>
114 for (
int i = WIDTH - 1; i >= 0; i--) {
123 template <
unsigned int BITS>
126 for (
int i = WIDTH - 1; i >= 2; i--) {
130 if (pn[1] != (b >> 32))
132 if (pn[0] != (b & 0xfffffffful))
137 template <
unsigned int BITS>
142 for (
int i = 0; i < WIDTH; i++) {
144 fact *= 4294967296.0;
149 template <
unsigned int BITS>
155 template <
unsigned int BITS>
161 template <
unsigned int BITS>
167 template <
unsigned int BITS>
173 template <
unsigned int BITS>
176 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
178 for (
int nbits = 31; nbits > 0; nbits--) {
179 if (pn[pos] & 1 << nbits)
180 return 32 * pos + nbits + 1;
208 int nSize = nCompact >> 24;
209 uint32_t nWord = nCompact & 0x007fffff;
211 nWord >>= 8 * (3 - nSize);
215 *
this <<= 8 * (nSize - 3);
218 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
220 *pfOverflow = nWord != 0 && ((nSize > 34) ||
221 (nWord > 0xff && nSize > 33) ||
222 (nWord > 0xffff && nSize > 32));
228 int nSize = (
bits() + 7) / 8;
229 uint32_t nCompact = 0;
231 nCompact =
GetLow64() << 8 * (3 - nSize);
238 if (nCompact & 0x00800000) {
242 assert((nCompact & ~0x007fffff) == 0);
244 nCompact |= nSize << 24;
245 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
252 for(
int x=0; x<a.
WIDTH; ++x)
259 for(
int x=0; x<b.
WIDTH; ++x)
bool EqualTo(uint64_t b) const
void SetHex(const char *psz)
std::string ToString() const
base_uint & operator/=(const base_uint &b)
static constexpr int WIDTH
static void WriteLE32(unsigned char *ptr, uint32_t x)
Template base class for unsigned big integers.
base_uint & operator<<=(unsigned int shift)
uint32_t GetCompact(bool fNegative=false) const
arith_uint256 UintToArith256(const uint256 &a)
uint256 uint256S(const char *str)
int CompareTo(const base_uint &b) const
256-bit unsigned big integer.
static uint32_t ReadLE32(const unsigned char *ptr)
uint256 ArithToUint256(const arith_uint256 &a)
uint64_t GetLow64() const
std::string GetHex() const
base_uint & operator*=(uint32_t b32)
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...
std::string GetHex() const
base_uint & operator>>=(unsigned int shift)
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.