| 221 | } |
| 222 | |
| 223 | uint32_t arith_uint256::GetCompact(bool fNegative) const |
| 224 | { |
| 225 | int nSize = (bits() + 7) / 8; |
| 226 | uint32_t nCompact = 0; |
| 227 | if (nSize <= 3) { |
| 228 | nCompact = GetLow64() << 8 * (3 - nSize); |
| 229 | } else { |
| 230 | arith_uint256 bn = *this >> 8 * (nSize - 3); |
| 231 | nCompact = bn.GetLow64(); |
| 232 | } |
| 233 | // The 0x00800000 bit denotes the sign. |
| 234 | // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. |
| 235 | if (nCompact & 0x00800000) { |
| 236 | nCompact >>= 8; |
| 237 | nSize++; |
| 238 | } |
| 239 | assert((nCompact & ~0x007fffffU) == 0); |
| 240 | assert(nSize < 256); |
| 241 | nCompact |= nSize << 24; |
| 242 | nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0); |
| 243 | return nCompact; |
| 244 | } |
| 245 | |
| 246 | uint256 ArithToUint256(const arith_uint256 &a) |
| 247 | { |