MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetCompact

Method GetCompact

src/arith_uint256.cpp:223–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223uint32_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
246uint256 ArithToUint256(const arith_uint256 &a)
247{

Callers 5

GetNextWorkRequiredFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
FUZZ_TARGET_INITFunction · 0.80

Calls 1

GetLow64Method · 0.80

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGET_INITFunction · 0.64