9 mpz_set(value, _value.get_mpz_t());
15 bool valueNegative = (mpz_sgn(value) == -1);
20 mpz_add_ui(value, value, 1);
25 std::size_t bitsPerBlock =
sizeof(Base::block_type) * CHAR_BIT;
26 std::size_t valueBits = mpz_sizeinbase(value, 2);
27 std::size_t blockCount = (valueBits + bitsPerBlock - 1) / bitsPerBlock;
31 auto bits = std::make_unique<Base::block_type[]>(blockCount);
32 mpz_export(&bits[0], &blockCount, -1,
sizeof(Base::block_type), -1, 0, value);
35 mValue.append(&bits[0], &bits[0] + blockCount);
48 concatenation.resize(
width() + _other.
width());
49 concatenation <<= _other.
width();
50 Base otherResized =
static_cast<Base>(_other);
51 otherResized.resize(concatenation.size());
52 concatenation |= otherResized;
53 return BVValue(std::move(concatenation));
59 bool firstNegative = (*this)[
width() - 1];
60 bool secondNegative = _other[_other.
width() - 1];
62 if (!firstNegative && !secondNegative) {
63 return (*
this) / _other;
64 }
else if (firstNegative && !secondNegative) {
65 return -(-(*this) / _other);
66 }
else if (!firstNegative && secondNegative) {
67 return -((*this) / -_other);
69 return -(*this) / -_other;
76 bool firstNegative = (*this)[
width() - 1];
77 bool secondNegative = _other[_other.
width() - 1];
79 if (!firstNegative && !secondNegative) {
80 return (*
this) % _other;
81 }
else if (firstNegative && !secondNegative) {
82 return -(-(*this) % _other);
83 }
else if (!firstNegative && secondNegative) {
84 return (*
this) % -_other;
86 return -((*this) % -_other);
93 bool firstNegative = (*this)[
width() - 1];
94 bool secondNegative = _other[_other.
width() - 1];
96 BVValue absFirst(firstNegative ? -(*
this) : (*
this));
97 BVValue absSecond(secondNegative ? -_other : _other);
99 BVValue u = absFirst % absSecond;
103 }
else if (!firstNegative && !secondNegative) {
105 }
else if (firstNegative && !secondNegative) {
107 }
else if (!firstNegative && secondNegative) {
108 return (*
this) + _other;
115 assert(_highest <
width() && _highest >= _lowest);
116 BVValue extraction(_highest - _lowest + 1);
118 for (std::size_t i = 0; i < extraction.
width(); ++i) {
119 extraction[i] = (*this)[_lowest + i];
126 std::size_t firstSize =
width() - 1;
127 std::size_t highestRelevantPos = 0;
129 bool fillWithOnes = !_left && _arithmetic && (*this)[
width() - 1];
131 while ((firstSize >>= 1) != 0)
132 ++highestRelevantPos;
134 for (std::size_t i = highestRelevantPos + 1; i < _other.
width(); ++i) {
137 return BVValue(fillWithOnes ? ~allZero : allZero);
142 std::size_t shiftBy = 1;
144 for (std::size_t i = 0; i <= highestRelevantPos && i < _other.
width(); ++i) {
155 return BVValue(fillWithOnes ? ~shifted : shifted);
163 std::size_t quotientIndex = 0;
164 Base divisor =
static_cast<Base>(_other);
167 while (!divisor[divisor.size() - 1] &&
remainder > divisor) {
177 for (std::size_t i = divisor.find_first(); i <
remainder.size(); ++i) {
178 bool newRemainderI = (
remainder[i] != divisor[i]) != carry;
179 carry = (
remainder[i] && carry && divisor[i]) || (!
remainder[i] && (carry || divisor[i]));
183 if (quotientIndex == 0) {
197 for (std::size_t i = 0; i < lhs.
width(); ++i) {
198 sum[i] = (lhs[i] != rhs[i]) != carry;
199 carry = (lhs[i] && rhs[i]) || (carry && (lhs[i] || rhs[i]));
201 return BVValue(std::move(sum));
209 for (std::size_t i = 0; i < lhs.
width(); ++i) {
carl is the main namespace for the library.
Interval< Number > operator+(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the addition of two intervals.
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
Interval< Number > operator*(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the multiplication of two intervals.
cln::cl_I remainder(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
BVValue modSigned(const BVValue &_other) const
BVValue extract(std::size_t _highest, std::size_t _lowest) const
BVValue concat(const BVValue &_other) const
BVValue divideUnsigned(const BVValue &_other, bool _returnRemainder=false) const
std::size_t width() const
BVValue shift(const BVValue &_other, bool _left, bool _arithmetic=false) const
boost::dynamic_bitset< uint > Base
const Base & base() const
BVValue divideSigned(const BVValue &_other) const
BVValue remSigned(const BVValue &_other) const