| 194 | } |
| 195 | |
| 196 | uint32_t arith_uint256::GetCompact(bool fNegative) const |
| 197 | { |
| 198 | int nSize = CeilDiv(bits(), 8u); |
| 199 | uint32_t nCompact = 0; |
| 200 | if (nSize <= 3) { |
| 201 | nCompact = GetLow64() << 8 * (3 - nSize); |
| 202 | } else { |
| 203 | arith_uint256 bn = *this >> 8 * (nSize - 3); |
| 204 | nCompact = bn.GetLow64(); |
| 205 | } |
| 206 | // The 0x00800000 bit denotes the sign. |
| 207 | // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. |
| 208 | if (nCompact & 0x00800000) { |
| 209 | nCompact >>= 8; |
| 210 | nSize++; |
| 211 | } |
| 212 | assert((nCompact & ~0x007fffffU) == 0); |
| 213 | assert(nSize < 256); |
| 214 | nCompact |= nSize << 24; |
| 215 | nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0); |
| 216 | return nCompact; |
| 217 | } |
| 218 | |
| 219 | uint256 ArithToUint256(const arith_uint256 &a) |
| 220 | { |