13template <
unsigned int BITS>
17 for (
int i = 0; i < WIDTH; i++)
21 for (
int i = 0; i < WIDTH; i++) {
22 if (i +
k + 1 < WIDTH && shift != 0)
23 pn[i +
k + 1] |= (a.
pn[i] >> (32 - shift));
25 pn[i +
k] |= (a.
pn[i] << shift);
30template <
unsigned int BITS>
34 for (
int i = 0; i < WIDTH; i++)
38 for (
int i = 0; i < WIDTH; i++) {
39 if (i -
k - 1 >= 0 && shift != 0)
40 pn[i -
k - 1] |= (a.
pn[i] << (32 - shift));
42 pn[i -
k] |= (a.
pn[i] >> shift);
47template <
unsigned int BITS>
51 for (
int i = 0; i < WIDTH; i++) {
52 uint64_t n = carry + (uint64_t)b32 * pn[i];
53 pn[i] = n & 0xffffffff;
59template <
unsigned int BITS>
63 for (
int j = 0; j < WIDTH; j++) {
65 for (
int i = 0; i + j < WIDTH; i++) {
66 uint64_t n = carry + a.
pn[i + j] + (uint64_t)pn[j] * b.
pn[i];
67 a.
pn[i + j] = n & 0xffffffff;
75template <
unsigned int BITS>
81 int num_bits = num.
bits();
82 int div_bits = div.
bits();
85 if (div_bits > num_bits)
87 int shift = num_bits - div_bits;
92 pn[shift / 32] |= (1U << (shift & 31));
101template <
unsigned int BITS>
104 for (
int i = WIDTH - 1; i >= 0; i--) {
113template <
unsigned int BITS>
116 for (
int i = WIDTH - 1; i >= 2; i--) {
120 if (pn[1] != (b >> 32))
122 if (pn[0] != (b & 0xfffffffful))
127template <
unsigned int BITS>
132 for (
int i = 0; i < WIDTH; i++) {
134 fact *= 4294967296.0;
139template <
unsigned int BITS>
143 for (
int x = 0; x < this->WIDTH; ++x) {
149template <
unsigned int BITS>
155template <
unsigned int BITS>
158 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
160 for (
int nbits = 31; nbits > 0; nbits--) {
161 if (pn[pos] & 1U << nbits)
162 return 32 * pos + nbits + 1;
177 int nSize = nCompact >> 24;
178 uint32_t nWord = nCompact & 0x007fffff;
180 nWord >>= 8 * (3 - nSize);
184 *
this <<= 8 * (nSize - 3);
187 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
189 *pfOverflow = nWord != 0 && ((nSize > 34) ||
190 (nWord > 0xff && nSize > 33) ||
191 (nWord > 0xffff && nSize > 32));
197 int nSize = (
bits() + 7) / 8;
198 uint32_t nCompact = 0;
207 if (nCompact & 0x00800000) {
211 assert((nCompact & ~0x007fffffU) == 0);
213 nCompact |= nSize << 24;
214 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
221 for(
int x=0; x<a.
WIDTH; ++x)
228 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.
constexpr unsigned char * begin()
std::string GetHex() const
Template base class for unsigned big integers.
int CompareTo(const base_uint &b) const
Numeric ordering (unlike base_blob::Compare)
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
std::string GetHex() const
Hex encoding of the number (with the most significant digits first).
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)