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>
172 template <
unsigned int BITS>
179 template <
unsigned int BITS>
182 SetReverseHex(str.c_str());
184 template <
unsigned int BITS>
190 template <
unsigned int BITS>
193 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
195 for (
int nbits = 31; nbits > 0; nbits--) {
196 if (pn[pos] & 1 << nbits)
197 return 32 * pos + nbits + 1;
228 int nSize = nCompact >> 24;
229 uint32_t nWord = nCompact & 0x007fffff;
231 nWord >>= 8 * (3 - nSize);
235 *
this <<= 8 * (nSize - 3);
238 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
240 *pfOverflow = nWord != 0 && ((nSize > 34) ||
241 (nWord > 0xff && nSize > 33) ||
242 (nWord > 0xffff && nSize > 32));
248 int nSize = (
bits() + 7) / 8;
249 uint32_t nCompact = 0;
251 nCompact =
GetLow64() << 8 * (3 - nSize);
258 if (nCompact & 0x00800000) {
262 assert((nCompact & ~0x007fffff) == 0);
264 nCompact |= nSize << 24;
265 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
void SetHex(const char *psz)
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.
base_uint & operator/=(const base_uint &b)
std::string GetHex() const
Template base class for unsigned big integers.
assert(len-trim+(2 *lenIndices)<=WIDTH)
base_uint & operator<<=(unsigned int shift)
arith_uint256 UintToArith256(const uint256 &a)
void SetReverseHex(const char *psz)
uint32_t GetCompact(bool fNegative=false) const
void SetReverseHex(const char *psz)
std::string GetReverseHex() const
uint256 uint256S(const char *str)
bool EqualTo(uint64_t b) const
std::string GetHex() const
friend uint256 ArithToUint256(const arith_uint256 &)
256-bit unsigned big integer.
int CompareTo(const base_uint &b) const
uint256 ArithToUint256(const arith_uint256 &a)
std::string ToString() const
std::string GetReverseHex() 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...
uint64_t GetLow64() const
friend arith_uint256 UintToArith256(const uint256 &)
base_uint & operator>>=(unsigned int shift)