MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetCompact

Method GetCompact

src/arith_uint256.cpp:196–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196uint32_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
219uint256 ArithToUint256(const arith_uint256 &a)
220{

Callers 8

GetNextWorkRequiredFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
integer.cppFile · 0.80
pow.cppFile · 0.80
ConsumeHeaderFunction · 0.80

Calls 2

CeilDivFunction · 0.85
GetLow64Method · 0.80

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
ConsumeHeaderFunction · 0.64