13 explicit uint_error(
const std::string& str) : std::runtime_error(str) {}
17 template<
unsigned int BITS>
21 enum { WIDTH=BITS/32 };
27 for (
int i = 0; i < WIDTH; i++)
33 for (
int i = 0; i < WIDTH; i++)
39 for (
int i = 0; i < WIDTH; i++)
46 pn[0] = (
unsigned int)b;
47 pn[1] = (
unsigned int)(b >> 32);
48 for (
int i = 2; i < WIDTH; i++)
52 explicit base_uint(
const std::string& str);
53 explicit base_uint(
const std::vector<unsigned char>& vch);
55 bool operator!()
const 57 for (
int i = 0; i < WIDTH; i++)
66 for (
int i = 0; i < WIDTH; i++)
74 for (
int i = 0; i < WIDTH; i++)
80 double getdouble()
const;
84 pn[0] = (
unsigned int)b;
85 pn[1] = (
unsigned int)(b >> 32);
86 for (
int i = 2; i < WIDTH; i++)
93 for (
int i = 0; i < WIDTH; i++)
100 for (
int i = 0; i < WIDTH; i++)
107 for (
int i = 0; i < WIDTH; i++)
114 pn[0] ^= (
unsigned int)b;
115 pn[1] ^= (
unsigned int)(b >> 32);
121 pn[0] |= (
unsigned int)b;
122 pn[1] |= (
unsigned int)(b >> 32);
126 base_uint& operator<<=(
unsigned int shift);
127 base_uint& operator>>=(
unsigned int shift);
132 for (
int i = 0; i < WIDTH; i++)
134 uint64_t n = carry + pn[i] + b.pn[i];
135 pn[i] = n & 0xffffffff;
171 while (++pn[i] == 0 && i < WIDTH-1)
188 while (--pn[i] == (uint32_t)-1 && i < WIDTH-1)
202 bool EqualTo(uint64_t b)
const;
214 friend inline bool operator==(
const base_uint& a,
const base_uint& b) {
return memcmp(a.pn, b.pn,
sizeof(a.pn)) == 0; }
215 friend inline bool operator!=(
const base_uint& a,
const base_uint& b) {
return memcmp(a.pn, b.pn,
sizeof(a.pn)) != 0; }
216 friend inline bool operator>(
const base_uint& a,
const base_uint& b) {
return a.CompareTo(b) > 0; }
217 friend inline bool operator<(
const base_uint& a,
const base_uint& b) {
return a.CompareTo(b) < 0; }
218 friend inline bool operator>=(
const base_uint& a,
const base_uint& b) {
return a.CompareTo(b) >= 0; }
219 friend inline bool operator<=(
const base_uint& a,
const base_uint& b) {
return a.CompareTo(b) <= 0; }
220 friend inline bool operator==(
const base_uint& a, uint64_t b) {
return a.EqualTo(b); }
221 friend inline bool operator!=(
const base_uint& a, uint64_t b) {
return !a.EqualTo(b); }
223 std::string GetHex()
const;
224 void SetHex(
const char* psz);
225 void SetHex(
const std::string& str);
226 std::string ToString()
const;
228 unsigned char* begin()
230 return (
unsigned char*)&pn[0];
235 return (
unsigned char*)&pn[WIDTH];
238 const unsigned char* begin()
const 240 return (
unsigned char*)&pn[0];
243 const unsigned char* end()
const 245 return (
unsigned char*)&pn[WIDTH];
248 unsigned int size()
const 257 unsigned int bits()
const;
259 uint64_t GetLow64()
const 262 return pn[0] | (uint64_t)pn[1] << 32;
265 unsigned int GetSerializeSize(
int nType,
int nVersion)
const 270 template<
typename Stream>
271 void Serialize(Stream& s,
int nType,
int nVersion)
const 273 s.write((
char*)pn,
sizeof(pn));
276 template<
typename Stream>
277 void Unserialize(Stream& s,
int nType,
int nVersion)
279 s.read((
char*)pn,
sizeof(pn));
322 uint256& SetCompact(uint32_t nCompact,
bool *pfNegative = NULL,
bool *pfOverflow = NULL);
323 uint32_t GetCompact(
bool fNegative =
false)
const;
325 uint64_t GetHash(
const uint256& salt)
const;
Definition: uint256.h:294
Definition: uint256.h:284