6 #ifndef BITCOIN_ARITH_UINT256_H 7 #define BITCOIN_ARITH_UINT256_H 20 explicit uint_error(
const std::string& str) :
std::runtime_error(str) {}
24 template<
unsigned int BITS>
28 static constexpr
int WIDTH = BITS / 32;
34 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
36 for (
int i = 0; i <
WIDTH; i++)
42 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
44 for (
int i = 0; i <
WIDTH; i++)
50 for (
int i = 0; i <
WIDTH; i++)
57 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
59 pn[0] = (
unsigned int)b;
60 pn[1] = (
unsigned int)(b >> 32);
61 for (
int i = 2; i <
WIDTH; i++)
65 explicit base_uint(
const std::string& str);
70 for (
int i = 0; i <
WIDTH; i++)
78 for (
int i = 0; i <
WIDTH; i++)
88 pn[0] = (
unsigned int)b;
89 pn[1] = (
unsigned int)(b >> 32);
90 for (
int i = 2; i <
WIDTH; i++)
97 for (
int i = 0; i <
WIDTH; i++)
104 for (
int i = 0; i <
WIDTH; i++)
111 for (
int i = 0; i <
WIDTH; i++)
118 pn[0] ^= (
unsigned int)b;
119 pn[1] ^= (
unsigned int)(b >> 32);
125 pn[0] |= (
unsigned int)b;
126 pn[1] |= (
unsigned int)(b >> 32);
136 for (
int i = 0; i <
WIDTH; i++)
138 uint64_t n = carry +
pn[i] + b.
pn[i];
139 pn[i] = n & 0xffffffff;
175 while (i <
WIDTH && ++
pn[i] == 0)
192 while (i <
WIDTH && --
pn[i] == (uint32_t)-1)
206 bool EqualTo(uint64_t b)
const;
227 std::string
GetHex()
const;
228 void SetHex(
const char* psz);
229 void SetHex(
const std::string& str);
241 unsigned int bits()
const;
245 static_assert(
WIDTH >= 2,
"Assertion WIDTH >= 2 failed (WIDTH = BITS / 32). BITS is a template parameter.");
246 return pn[0] | (uint64_t)
pn[1] << 32;
279 uint32_t
GetCompact(
bool fNegative =
false)
const;
288 #endif // BITCOIN_ARITH_UINT256_H bool EqualTo(uint64_t b) const
base_uint & operator=(const base_uint &b)
void SetHex(const char *psz)
friend const base_uint operator^(const base_uint &a, const base_uint &b)
base_uint & operator &=(const base_uint &b)
arith_uint256(const std::string &str)
std::string ToString() const
const base_uint operator~() const
friend const base_uint operator*(const base_uint &a, uint32_t b)
base_uint & operator|=(uint64_t b)
base_uint & operator/=(const base_uint &b)
friend const base_uint operator &(const base_uint &a, const base_uint &b)
static constexpr int WIDTH
UniValue ret(UniValue::VARR)
friend bool operator!=(const base_uint &a, uint64_t b)
base_uint & operator+=(const base_uint &b)
friend bool operator<=(const base_uint &a, const base_uint &b)
base_uint & operator|=(const base_uint &b)
base_uint & operator-=(uint64_t b64)
friend bool operator>(const base_uint &a, const base_uint &b)
Template base class for unsigned big integers.
friend const base_uint operator-(const base_uint &a, const base_uint &b)
base_uint & operator<<=(unsigned int shift)
base_uint & operator+=(uint64_t b64)
friend const base_uint operator/(const base_uint &a, const base_uint &b)
uint32_t GetCompact(bool fNegative=false) const
base_uint & operator-=(const base_uint &b)
friend bool operator==(const base_uint &a, const base_uint &b)
friend const base_uint operator+(const base_uint &a, const base_uint &b)
friend bool operator<(const base_uint &a, const base_uint &b)
uint256 ArithToUint256(const arith_uint256 &)
base_uint(const base_uint &b)
friend const base_uint operator*(const base_uint &a, const base_uint &b)
int CompareTo(const base_uint &b) const
uint_error(const std::string &str)
base_uint & operator^=(uint64_t b)
friend uint256 ArithToUint256(const arith_uint256 &)
256-bit unsigned big integer.
friend bool operator!=(const base_uint &a, const base_uint &b)
uint64_t GetLow64() const
friend const base_uint operator|(const base_uint &a, const base_uint &b)
const base_uint operator-() const
arith_uint256(uint64_t b)
base_uint & operator*=(uint32_t b32)
base_uint & operator=(uint64_t b)
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...
const base_uint operator--(int)
std::string GetHex() const
const base_uint operator++(int)
friend const base_uint operator<<(const base_uint &a, int shift)
friend bool operator>=(const base_uint &a, const base_uint &b)
arith_uint256(const base_uint< 256 > &b)
arith_uint256 UintToArith256(const uint256 &)
unsigned int size() const
friend bool operator==(const base_uint &a, uint64_t b)
friend const base_uint operator>>(const base_uint &a, int shift)
friend arith_uint256 UintToArith256(const uint256 &)
base_uint & operator^=(const base_uint &b)
base_uint & operator>>=(unsigned int shift)
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.