6 #ifndef BITCOIN_ARITH_UINT256_H 7 #define BITCOIN_ARITH_UINT256_H 21 explicit uint_error(
const std::string& str) : std::runtime_error(str) {}
25 template<
unsigned int BITS>
29 static constexpr
int 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);
71 for (
int i = 0; i <
WIDTH; i++)
79 for (
int i = 0; i <
WIDTH; i++)
89 pn[0] = (
unsigned int)b;
90 pn[1] = (
unsigned int)(b >> 32);
91 for (
int i = 2; i <
WIDTH; i++)
98 for (
int i = 0; i <
WIDTH; i++)
105 for (
int i = 0; i <
WIDTH; i++)
112 for (
int i = 0; i <
WIDTH; i++)
119 pn[0] ^= (
unsigned int)b;
120 pn[1] ^= (
unsigned int)(b >> 32);
126 pn[0] |= (
unsigned int)b;
127 pn[1] |= (
unsigned int)(b >> 32);
137 for (
int i = 0; i <
WIDTH; i++)
140 pn[i] = n & 0xffffffff;
176 while (i <
WIDTH && ++
pn[i] == 0)
193 while (i <
WIDTH && --
pn[i] == std::numeric_limits<uint32_t>::max())
228 std::string
GetHex()
const;
229 void SetHex(
const char* psz);
230 void SetHex(
const std::string& str);
242 unsigned int bits()
const;
246 static_assert(
WIDTH >= 2,
"Assertion WIDTH >= 2 failed (WIDTH = BITS / 32). BITS is a template parameter.");
289 #endif // BITCOIN_ARITH_UINT256_H bool EqualTo(uint64_t b) const
Definition: arith_uint256.cpp:123
base_uint & operator=(const base_uint &b)
Definition: arith_uint256.h:49
void SetHex(const char *psz)
Definition: arith_uint256.cpp:155
friend const base_uint operator^(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:215
arith_uint256(const std::string &str)
Definition: arith_uint256.h:257
std::string ToString() const
Definition: arith_uint256.cpp:167
const base_uint operator~() const
Definition: arith_uint256.h:68
base_uint & operator|=(uint64_t b)
Definition: arith_uint256.h:124
base_uint & operator/=(const base_uint &b)
Definition: arith_uint256.cpp:85
static constexpr int WIDTH
Definition: arith_uint256.h:29
friend bool operator!=(const base_uint &a, uint64_t b)
Definition: arith_uint256.h:226
base_uint & operator+=(const base_uint &b)
Definition: arith_uint256.h:134
friend bool operator<=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:224
base_uint & operator|=(const base_uint &b)
Definition: arith_uint256.h:110
base_uint & operator-=(uint64_t b64)
Definition: arith_uint256.h:160
friend bool operator>(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:221
Definition: arith_uint256.h:26
base_uint & operator *=(uint32_t b32)
Definition: arith_uint256.cpp:57
friend const base_uint operator-(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:210
base_uint & operator<<=(unsigned int shift)
Definition: arith_uint256.cpp:23
arith_uint256()
Definition: arith_uint256.h:254
base_uint & operator+=(uint64_t b64)
Definition: arith_uint256.h:152
friend const base_uint operator/(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:212
uint32_t GetCompact(bool fNegative=false) const
Definition: arith_uint256.cpp:225
Definition: arith_uint256.h:19
base_uint & operator--()
Definition: arith_uint256.h:189
base_uint & operator&=(const base_uint &b)
Definition: arith_uint256.h:103
uint32_t pn[WIDTH]
Definition: arith_uint256.h:30
base_uint & operator-=(const base_uint &b)
Definition: arith_uint256.h:146
friend bool operator==(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:219
friend const base_uint operator+(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:209
base_uint(uint64_t b)
Definition: arith_uint256.h:56
friend bool operator<(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:222
unsigned int uint32_t
Definition: stdint.h:21
friend const base_uint operator &(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:214
uint256 ArithToUint256(const arith_uint256 &)
Definition: arith_uint256.cpp:248
base_uint(const base_uint &b)
Definition: arith_uint256.h:41
unsigned long long uint64_t
Definition: stdint.h:22
int CompareTo(const base_uint &b) const
Definition: arith_uint256.cpp:111
uint_error(const std::string &str)
Definition: arith_uint256.h:21
base_uint & operator^=(uint64_t b)
Definition: arith_uint256.h:117
friend uint256 ArithToUint256(const arith_uint256 &)
Definition: arith_uint256.cpp:248
Definition: arith_uint256.h:252
Definition: uint256.h:121
base_uint & operator++()
Definition: arith_uint256.h:172
friend bool operator!=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:220
uint64_t GetLow64() const
Definition: arith_uint256.h:244
friend const base_uint operator|(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:213
friend const base_uint operator *(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:211
const base_uint operator-() const
Definition: arith_uint256.h:76
arith_uint256(uint64_t b)
Definition: arith_uint256.h:256
base_uint & operator=(uint64_t b)
Definition: arith_uint256.h:87
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
Definition: arith_uint256.cpp:205
const base_uint operator--(int)
Definition: arith_uint256.h:198
std::string GetHex() const
Definition: arith_uint256.cpp:149
const base_uint operator++(int)
Definition: arith_uint256.h:181
friend const base_uint operator<<(const base_uint &a, int shift)
Definition: arith_uint256.h:217
friend bool operator>=(const base_uint &a, const base_uint &b)
Definition: arith_uint256.h:223
arith_uint256(const base_uint< 256 > &b)
Definition: arith_uint256.h:255
arith_uint256 UintToArith256(const uint256 &)
Definition: arith_uint256.cpp:255
unsigned int size() const
Definition: arith_uint256.h:233
double getdouble() const
Definition: arith_uint256.cpp:137
friend bool operator==(const base_uint &a, uint64_t b)
Definition: arith_uint256.h:225
friend const base_uint operator>>(const base_uint &a, int shift)
Definition: arith_uint256.h:216
friend arith_uint256 UintToArith256(const uint256 &)
Definition: arith_uint256.cpp:255
base_uint & operator^=(const base_uint &b)
Definition: arith_uint256.h:96
base_uint()
Definition: arith_uint256.h:33
base_uint & operator>>=(unsigned int shift)
Definition: arith_uint256.cpp:40
unsigned int bits() const
Definition: arith_uint256.cpp:173