15 template <
unsigned int BITS>
21 template <
unsigned int BITS>
25 for (
int i = 0; i < WIDTH; i++)
29 for (
int i = 0; i < WIDTH; i++) {
30 if (i + k + 1 < WIDTH && shift != 0)
31 pn[i + k + 1] |= (a.pn[i] >> (32 - shift));
33 pn[i + k] |= (a.pn[i] << shift);
38 template <
unsigned int BITS>
42 for (
int i = 0; i < WIDTH; i++)
46 for (
int i = 0; i < WIDTH; i++) {
47 if (i - k - 1 >= 0 && shift != 0)
48 pn[i - k - 1] |= (a.
pn[i] << (32 - shift));
50 pn[i - k] |= (a.
pn[i] >> shift);
55 template <
unsigned int BITS>
59 for (
int i = 0; i < WIDTH; i++) {
60 uint64_t n = carry + (uint64_t)b32 * pn[i];
61 pn[i] = n & 0xffffffff;
67 template <
unsigned int BITS>
72 for (
int j = 0; j < WIDTH; j++) {
74 for (
int i = 0; i + j < WIDTH; i++) {
75 uint64_t n = carry + pn[i + j] + (uint64_t)a.
pn[j] * b.
pn[i];
76 pn[i + j] = n & 0xffffffff;
83 template <
unsigned int BITS>
89 int num_bits = num.
bits();
90 int div_bits = div.
bits();
93 if (div_bits > num_bits)
95 int shift = num_bits - div_bits;
100 pn[shift / 32] |= (1 << (shift & 31));
109 template <
unsigned int BITS>
112 for (
int i = WIDTH - 1; i >= 0; i--) {
121 template <
unsigned int BITS>
124 for (
int i = WIDTH - 1; i >= 2; i--) {
128 if (pn[1] != (b >> 32))
130 if (pn[0] != (b & 0xfffffffful))
135 template <
unsigned int BITS>
140 for (
int i = 0; i < WIDTH; i++) {
142 fact *= 4294967296.0;
147 template <
unsigned int BITS>
153 template <
unsigned int BITS>
159 template <
unsigned int BITS>
165 template <
unsigned int BITS>
171 template <
unsigned int BITS>
174 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
176 for (
int bits = 31; bits > 0; bits--) {
177 if (pn[pos] & 1 << bits)
178 return 32 * pos + bits + 1;
206 int nSize = nCompact >> 24;
207 uint32_t nWord = nCompact & 0x007fffff;
209 nWord >>= 8 * (3 - nSize);
213 *
this <<= 8 * (nSize - 3);
216 *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
218 *pfOverflow = nWord != 0 && ((nSize > 34) ||
219 (nWord > 0xff && nSize > 33) ||
220 (nWord > 0xffff && nSize > 32));
226 int nSize = (
bits() + 7) / 8;
227 uint32_t nCompact = 0;
236 if (nCompact & 0x00800000) {
240 assert((nCompact & ~0x007fffff) == 0);
242 nCompact |= nSize << 24;
243 nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
250 for(
int x=0; x<a.
WIDTH; ++x)
251 WriteLE32(b.
begin() + x*4, a.
pn[x]);
257 for(
int x=0; x<b.
WIDTH; ++x)
258 b.
pn[x] = ReadLE32(a.
begin() + x*4);
arith_uint256 UintToArith256(const uint256 &a)
uint256 ArithToUint256(const arith_uint256 &a)
256-bit unsigned big integer.
uint32_t GetCompact(bool fNegative=false) const
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=NULL, bool *pfOverflow=NULL)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
std::string GetHex() const
Template base class for unsigned big integers.
int CompareTo(const base_uint &b) const
base_uint & operator>>=(unsigned int shift)
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.
uint256 uint256S(const char *str)