X BigInteger::convertToSignedPrimitive() const { if (sign == zero) return 0; else if (mag.getLength() == 1) { // The single block might fit in an X. Try the conversion. Blk b = mag.getBlock(0); if (sign == positive) { X x = X(b); if (x >= 0 && Blk(x) == b) return x; } else { X x = -X(b); /* UX(...) needed to avoid rejecting conversion of * -2^15 to a short. */ if (x < 0 && Blk(UX(-x)) == b) return x; } // Otherwise fall through. } throw "BigInteger::to<Primitive>: " "Value is too big to fit in the requested type"; }
SL::Remote_Access_Library::Utilities::Blk SL::Remote_Access_Library::Utilities::BufferManager::AquireBuffer(size_t req_bytes) { if (req_bytes == 0) return Blk(); std::lock_guard<std::mutex> lock(_BufferManagerImpl->_BufferLock); _BufferManagerImpl->Total_OutStanding += req_bytes; auto found = std::find_if(begin(_BufferManagerImpl->_Buffer), end(_BufferManagerImpl->_Buffer), [req_bytes](const SL::Remote_Access_Library::Utilities::Blk& c) { return c.size >= req_bytes; }); if (found == _BufferManagerImpl->_Buffer.end()) { std::cout << "new " << std::endl; SL::Remote_Access_Library::Utilities::Blk b; b.data = new char[req_bytes]; b.size = req_bytes; return b; } else { std::cout << "used " << _BufferManagerImpl->_Bytes_Allocated << std::endl; auto ret(*found); _BufferManagerImpl->_Bytes_Allocated -= ret.size; _BufferManagerImpl->_Buffer.erase(found); return ret; } }
void BigUnsigned::setBit(Index bi, bool newBit) { Index blockI = bi / N; Blk block = getBlock(blockI), mask = Blk(1) << (bi % N); block = newBit ? (block | mask) : (block & ~mask); setBlock(blockI, block); }