7 #ifndef RAVEN_ARITH_UINT256_H 8 #define RAVEN_ARITH_UINT256_H 21 explicit uint_error(
const std::string& str) :
std::runtime_error(str) {}
25 template<
unsigned int BITS>
29 enum { WIDTH=BITS/32 };
35 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
37 for (
int i = 0; i < WIDTH; i++)
43 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
45 for (
int i = 0; i < WIDTH; i++)
51 for (
int i = 0; i < WIDTH; i++)
58 static_assert(BITS/32 > 0 && BITS%32 == 0,
"Template parameter BITS must be a positive multiple of 32.");
60 pn[0] = (
unsigned int)b;
61 pn[1] = (
unsigned int)(b >> 32);
62 for (
int i = 2; i < WIDTH; i++)
66 explicit base_uint(
const std::string& str);
70 for (
int i = 0; i < WIDTH; i++)
79 for (
int i = 0; i < WIDTH; i++)
87 for (
int i = 0; i < WIDTH; i++)
93 double getdouble()
const;
97 pn[0] = (
unsigned int)b;
98 pn[1] = (
unsigned int)(b >> 32);
99 for (
int i = 2; i < WIDTH; i++)
106 for (
int i = 0; i < WIDTH; i++)
113 for (
int i = 0; i < WIDTH; i++)
120 for (
int i = 0; i < WIDTH; i++)
127 pn[0] ^= (
unsigned int)b;
128 pn[1] ^= (
unsigned int)(b >> 32);
134 pn[0] |= (
unsigned int)b;
135 pn[1] |= (
unsigned int)(b >> 32);
139 base_uint& operator<<=(
unsigned int shift);
140 base_uint& operator>>=(
unsigned int shift);
145 for (
int i = 0; i < WIDTH; i++)
147 uint64_t n = carry + pn[i] + b.
pn[i];
148 pn[i] = n & 0xffffffff;
184 while (i < WIDTH && ++pn[i] == 0)
201 while (i < WIDTH && --pn[i] == (uint32_t)-1)
215 bool EqualTo(uint64_t b)
const;
236 std::string GetHex()
const;
237 void SetHex(
const char* psz);
238 void SetHex(
const std::string& str);
239 std::string ToString()
const;
250 unsigned int bits()
const;
254 static_assert(WIDTH >= 2,
"Assertion WIDTH >= 2 failed (WIDTH = BITS / 32). BITS is a template parameter.");
255 return pn[0] | (uint64_t)pn[1] << 32;
287 arith_uint256& SetCompact(uint32_t nCompact,
bool *pfNegative =
nullptr,
bool *pfOverflow =
nullptr);
288 uint32_t GetCompact(
bool fNegative =
false)
const;
297 #endif // RAVEN_ARITH_UINT256_H bool EqualTo(uint64_t b) const
base_uint & operator=(const base_uint &b)
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)
const base_uint operator~() const
friend const base_uint operator*(const base_uint &a, uint32_t b)
base_uint & operator|=(uint64_t b)
friend const base_uint operator &(const base_uint &a, const base_uint &b)
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+=(uint64_t b64)
friend const base_uint operator/(const base_uint &a, const base_uint &b)
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)
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=(uint64_t b)
const base_uint operator--(int)
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)
base_uint & operator^=(const base_uint &b)