13template <
unsigned int BITS>
15 static_assert(BITS / 32 > 0 && BITS % 32 == 0,
16 "Template parameter BITS must be a positive multiple of 32.");
21template <
unsigned int BITS>
24 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));
34 pn[i + k] |= (
a.pn[i] <<
shift);
40template <
unsigned int BITS>
43 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));
53 pn[i - k] |= (
a.pn[i] >>
shift);
59template <
unsigned int BITS>
62 for (
int i = 0; i < WIDTH; i++) {
64 pn[i] = n & 0xffffffff;
70template <
unsigned int BITS>
73 for (
int j = 0;
j < WIDTH;
j++) {
75 for (
int i = 0; i +
j < WIDTH; i++) {
77 a.pn[i +
j] = n & 0xffffffff;
85template <
unsigned int BITS>
119template <
unsigned int BITS>
121 for (
int i = WIDTH - 1; i >= 0; i--) {
122 if (pn[i] <
b.pn[i]) {
125 if (pn[i] >
b.pn[i]) {
133 for (
int i = WIDTH - 1; i >= 2; i--) {
138 if (pn[1] != (
b >> 32)) {
141 if (pn[0] != (
b & 0xfffffffful)) {
150 for (
int i = 0; i < WIDTH; i++) {
152 fact *= 4294967296.0;
165template <
unsigned int BITS>
175 for (
int pos = WIDTH - 1; pos >= 0; pos--) {
178 if (pn[pos] & 1U <<
nbits) {
179 return 32 * pos +
nbits + 1;
211 nWord >>= 8 * (3 - nSize);
215 *
this <<= 8 * (nSize - 3);
222 nWord != 0 && ((nSize > 34) || (
nWord > 0xff && nSize > 33) ||
223 (
nWord > 0xffff && nSize > 32));
229 int nSize = (
bits() + 7) / 8;
253 for (
int i =
b.WIDTH - 1; i >= 0; i--) {
254 const double fact = std::pow(4294967296.0, i);
263 for (
int x = 0; x <
a.WIDTH; ++x) {
270 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)
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.
static void WriteLE32(uint8_t *ptr, uint32_t x)
static uint32_t ReadLE32(const uint8_t *ptr)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
uint256 uint256S(const char *str)
uint256 from const char *.