update some main files

This commit is contained in:
Michel van Kessel
2020-12-21 00:01:41 +01:00
parent 1c40a60f2c
commit ade5bb46e5
19 changed files with 152 additions and 147 deletions

View File

@@ -15,20 +15,21 @@
class uint256;
class uint_error : public std::runtime_error {
class uint_error : public std::runtime_error
{
public:
explicit uint_error(const std::string& str) : std::runtime_error(str) {}
};
/** Template base class for unsigned big integers. */
template<unsigned int BITS>
template <unsigned int BITS>
class base_uint
{
protected:
enum { WIDTH=BITS/32 };
enum { WIDTH = BITS / 32 };
uint32_t pn[WIDTH];
public:
public:
base_uint()
{
for (int i = 0; i < WIDTH; i++)
@@ -135,8 +136,7 @@ public:
base_uint& operator+=(const base_uint& b)
{
uint64_t carry = 0;
for (int i = 0; i < WIDTH; i++)
{
for (int i = 0; i < WIDTH; i++) {
uint64_t n = carry + pn[i] + b.pn[i];
pn[i] = n & 0xffffffff;
carry = n >> 32;
@@ -174,7 +174,7 @@ public:
{
// prefix operator
int i = 0;
while (++pn[i] == 0 && i < WIDTH-1)
while (++pn[i] == 0 && i < WIDTH - 1)
i++;
return *this;
}
@@ -191,7 +191,7 @@ public:
{
// prefix operator
int i = 0;
while (--pn[i] == (uint32_t)-1 && i < WIDTH-1)
while (--pn[i] == (uint32_t)-1 && i < WIDTH - 1)
i++;
return *this;
}
@@ -250,7 +250,8 @@ public:
};
/** 256-bit unsigned big integer. */
class arith_uint256 : public base_uint<256> {
class arith_uint256 : public base_uint<256>
{
public:
arith_uint256() {}
arith_uint256(const base_uint<256>& b) : base_uint<256>(b) {}
@@ -277,11 +278,11 @@ public:
* complexities of the sign bit and using base 256 are probably an
* implementation accident.
*/
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
arith_uint256& SetCompact(uint32_t nCompact, bool* pfNegative = NULL, bool* pfOverflow = NULL);
uint32_t GetCompact(bool fNegative = false) const;
friend uint256 ArithToUint256(const arith_uint256 &);
friend arith_uint256 UintToArith256(const uint256 &);
friend uint256 ArithToUint256(const arith_uint256&);
friend arith_uint256 UintToArith256(const uint256&);
};
uint256 ArithToUint256(const arith_uint256 &);