14template <
unsigned int BITS>
17 for (
int i = 0; i < WIDTH; i++) {
22 for (
int i = 0; i < WIDTH; i++) {
23 if (i + k + 1 < WIDTH && shift != 0) {
24 pn[i + k + 1] |= (a.
pn[i] >> (32 - shift));
27 pn[i + k] |= (a.
pn[i] << shift);
33template <
unsigned int BITS>
36 for (
int i = 0; i < WIDTH; i++) {
41 for (
int i = 0; i < WIDTH; i++) {
42 if (i - k - 1 >= 0 && shift != 0) {
43 pn[i - k - 1] |= (a.
pn[i] << (32 - shift));
46 pn[i - k] |= (a.
pn[i] >> shift);
52template <
unsigned int BITS>
55 for (
int i = 0; i < WIDTH; i++) {
56 uint64_t n = carry + (uint64_t)b32 * pn[i];
57 pn[i] = n & 0xffffffff;
63template <
unsigned int BITS>
66 for (
int j = 0; j < WIDTH; j++) {
68 for (
int i = 0; i + j < WIDTH; i++) {
69 uint64_t n = carry + a.
pn[i + j] + (uint64_t)pn[j] * b.
pn[i];
70 a.
pn[i + j] = n & 0xffffffff;
78template <
unsigned int BITS>
86 int num_bits = num.
bits();
87 int div_bits = div.
bits();
92 if (div_bits > num_bits) {
95 int shift = num_bits - div_bits;
102 pn[shift / 32] |= (1U << (shift & 31));
112template <
unsigned int BITS>
114 for (
int i = WIDTH - 1; i >= 0; i--) {
115 if (pn[i] < b.
pn[i]) {
118 if (pn[i] > b.
pn[i]) {
126 for (
int i = WIDTH - 1; i >= 2; i--) {
131 if (pn[1] != (b >> 32)) {
134 if (pn[0] != (b & 0xfffffffful)) {
143 for (
int i = 0; i < WIDTH; i++) {
145 fact *= 4294967296.0;
159 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
161 for (
int nbits = 31; nbits > 0; nbits--) {
162 if (pn[pos] & 1U << nbits) {
163 return 32 * pos + nbits + 1;
189 int nSize = nCompact >> 24;
190 uint32_t nWord = nCompact & 0x007fffff;
192 nWord >>= 8 * (3 - nSize);
196 *
this <<= 8 * (nSize - 3);
199 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
203 nWord != 0 && ((nSize > 34) || (nWord > 0xff && nSize > 33) ||
204 (nWord > 0xffff && nSize > 32));
210 int nSize = (
bits() + 7) / 8;
211 uint32_t nCompact = 0;
213 nCompact =
GetLow64() << 8 * (3 - nSize);
221 if (nCompact & 0x00800000) {
225 assert((nCompact & ~0x007fffffU) == 0);
227 nCompact |= nSize << 24;
228 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
234 for (
int i = b.
WIDTH - 1; i >= 0; i--) {
235 const double fact = std::pow(4294967296.0, i);
236 b.
pn[i] = uint32_t(d / fact);
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
static arith_uint256 fromDouble(double d)
constexpr uint8_t * begin()
std::string GetHex() const
Template base class for unsigned big integers.
base_uint & operator/=(const base_uint &b)
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
uint64_t GetLow64() const
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 void WriteLE32(uint8_t *ptr, uint32_t x)
static uint32_t ReadLE32(const uint8_t *ptr)