diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-05-09 16:57:06 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-05-09 17:03:51 +0200 |
commit | 8bcfccbc2de25e3b40d1c222d7c5d9991345a0aa (patch) | |
tree | ec29908109f159efce4c7ccb6bba68125b1d04e8 /src/bignum.h | |
parent | 82564e21e79092a7e28aa5d31d8fdbdb3fd970ca (diff) | |
parent | 397668ea63e148a92f68e9fae578595585616770 (diff) |
Merge pull request #4076
397668e Deduplicate uint* comparison operator logic (Pieter Wuille)
df9eb5e Move {Get,Set}Compact from bignum to uint256 (Pieter Wuille)
a703150 Add multiplication and division to uint160/uint256 (Pieter Wuille)
4d480c8 Exception instead of assigning 0 in case of wrong vector length (Pieter Wuille)
eb2cbd7 Deduplicate shared code between uint160 and uint256 (Pieter Wuille)
Diffstat (limited to 'src/bignum.h')
-rw-r--r-- | src/bignum.h | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/bignum.h b/src/bignum.h index 0259338b31..6b77462d83 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -269,71 +269,6 @@ public: return vch; } - // The "compact" format is a representation of a whole - // number N using an unsigned 32bit number similar to a - // floating point format. - // The most significant 8 bits are the unsigned exponent of base 256. - // This exponent can be thought of as "number of bytes of N". - // The lower 23 bits are the mantissa. - // Bit number 24 (0x800000) represents the sign of N. - // N = (-1^sign) * mantissa * 256^(exponent-3) - // - // Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). - // MPI uses the most significant bit of the first byte as sign. - // Thus 0x1234560000 is compact (0x05123456) - // and 0xc0de000000 is compact (0x0600c0de) - // (0x05c0de00) would be -0x40de000000 - // - // Bitcoin only uses this "compact" format for encoding difficulty - // targets, which are unsigned 256bit quantities. Thus, all the - // complexities of the sign bit and using base 256 are probably an - // implementation accident. - // - // This implementation directly uses shifts instead of going - // through an intermediate MPI representation. - CBigNum& SetCompact(unsigned int nCompact) - { - unsigned int nSize = nCompact >> 24; - bool fNegative =(nCompact & 0x00800000) != 0; - unsigned int nWord = nCompact & 0x007fffff; - if (nSize <= 3) - { - nWord >>= 8*(3-nSize); - BN_set_word(this, nWord); - } - else - { - BN_set_word(this, nWord); - BN_lshift(this, this, 8*(nSize-3)); - } - BN_set_negative(this, fNegative); - return *this; - } - - unsigned int GetCompact() const - { - unsigned int nSize = BN_num_bytes(this); - unsigned int nCompact = 0; - if (nSize <= 3) - nCompact = BN_get_word(this) << 8*(3-nSize); - else - { - CBigNum bn; - BN_rshift(&bn, this, 8*(nSize-3)); - nCompact = BN_get_word(&bn); - } - // The 0x00800000 bit denotes the sign. - // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. - if (nCompact & 0x00800000) - { - nCompact >>= 8; - nSize++; - } - nCompact |= nSize << 24; - nCompact |= (BN_is_negative(this) ? 0x00800000 : 0); - return nCompact; - } - void SetHex(const std::string& str) { // skip 0x |