6 #ifndef FABCOIN_ARITH_UINT256_H 7 #define FABCOIN_ARITH_UINT256_H 20 explicit uint_error(
const std::string& str) :
std::runtime_error(str) {}
24 template<
unsigned int BITS>
28 enum { 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);
69 for (
int i = 0; i < WIDTH; i++)
78 for (
int i = 0; i < WIDTH; i++)
86 for (
int i = 0; i < WIDTH; i++)
92 double getdouble()
const;
96 pn[0] = (
unsigned int)b;
97 pn[1] = (
unsigned int)(b >> 32);
98 for (
int i = 2; i < WIDTH; i++)
105 for (
int i = 0; i < WIDTH; i++)
112 for (
int i = 0; i < WIDTH; i++)
119 for (
int i = 0; i < WIDTH; i++)
126 pn[0] ^= (
unsigned int)b;
127 pn[1] ^= (
unsigned int)(b >> 32);
133 pn[0] |= (
unsigned int)b;
134 pn[1] |= (
unsigned int)(b >> 32);
138 base_uint& operator<<=(
unsigned int shift);
139 base_uint& operator>>=(
unsigned int shift);
144 for (
int i = 0; i < WIDTH; i++)
146 uint64_t n = carry + pn[i] + b.
pn[i];
147 pn[i] = n & 0xffffffff;
183 while (i < WIDTH && ++pn[i] == 0)
200 while (i < WIDTH && --pn[i] == (uint32_t)-1)
214 bool EqualTo(uint64_t b)
const;
235 std::string GetHex()
const;
236 void SetHex(
const char* psz);
237 void SetHex(
const std::string& str);
238 std::string GetReverseHex()
const;
239 void SetReverseHex(
const char* psz);
240 void SetReverseHex(
const std::string& str);
241 std::string ToString()
const;
252 unsigned int bits()
const;
257 return pn[0] | (uint64_t)pn[1] << 32;
289 arith_uint256& SetCompact(uint32_t nCompact,
bool *pfNegative =
nullptr,
bool *pfOverflow =
nullptr);
290 uint32_t GetCompact(
bool fNegative =
false)
const;
299 #endif // FABCOIN_ARITH_UINT256_H base_uint & operator=(const base_uint &b)
friend const base_uint operator^(const base_uint &a, const base_uint &b)
arith_uint256(const std::string &str)
friend const base_uint operator*(const base_uint &a, uint32_t b)
base_uint & operator|=(uint64_t b)
const base_uint operator-() const
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.
std::hash for asio::adress
friend const base_uint operator-(const base_uint &a, const base_uint &b)
assert(len-trim+(2 *lenIndices)<=WIDTH)
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)
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)
uint_error(const std::string &str)
bool EqualTo(uint64_t b) const
base_uint & operator^=(uint64_t b)
friend const base_uint operator&(const base_uint &a, const base_uint &b)
256-bit unsigned big integer.
int CompareTo(const base_uint &b) const
friend bool operator!=(const base_uint &a, const base_uint &b)
friend const base_uint operator|(const base_uint &a, const base_uint &b)
arith_uint256(uint64_t b)
base_uint & operator=(uint64_t b)
const base_uint operator--(int)
const base_uint operator~() 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
uint64_t GetLow64() 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)