Skip to content

Commit e6607df

Browse files
committed
fixes
1 parent fdc5793 commit e6607df

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

src/util/mpz.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,14 +1775,15 @@ template<bool SYNCH>
17751775
void mpz_manager<SYNCH>::power(mpz const & a, unsigned p, mpz & b) {
17761776
STRACE(mpz, tout << "power(" << to_string(a) << ", " << p << ") == ";);
17771777
#ifdef _MP_GMP
1778-
if (!is_small(a)) {
1778+
if (a.has_ptr()) {
17791779
mk_big(b);
17801780
mpz_pow_ui(*b.ptr(), *a.ptr(), p);
17811781
return;
17821782
}
17831783
#else
17841784
if (is_small(a)) {
1785-
if (a.value() == 2) {
1785+
int64_t v = a.value();
1786+
if (v == 2) {
17861787
if (p < 63) {
17871788
set(b, int64_t(1ull << p));
17881789
}
@@ -1797,16 +1798,20 @@ void mpz_manager<SYNCH>::power(mpz const & a, unsigned p, mpz & b) {
17971798
b.ptr()->m_digits[sz-1] = digit_t(1ULL << shift);
17981799
b.set_sign(1);
17991800
}
1801+
STRACE(mpz, tout << to_string(b) << '\n';);
1802+
return;
18001803
}
1801-
else if (a.value() == 0) {
1804+
else if (v == 0) {
18021805
SASSERT(p != 0);
18031806
set(b, 0);
1807+
STRACE(mpz, tout << to_string(b) << '\n';);
1808+
return;
18041809
}
1805-
else if (a.value() == 1) {
1810+
else if (v == 1) {
18061811
set(b, 1);
1812+
STRACE(mpz, tout << to_string(b) << '\n';);
1813+
return;
18071814
}
1808-
STRACE(mpz, tout << to_string(b) << '\n';);
1809-
return;
18101815
}
18111816
#endif
18121817
// general purpose
@@ -1921,10 +1926,20 @@ void mpz_manager<SYNCH>::normalize(mpz & a) {
19211926

19221927
template<bool SYNCH>
19231928
void mpz_manager<SYNCH>::machine_div2k(mpz & a, unsigned k) {
1929+
STRACE(mpz, tout << "[mpz-machine-div2k] a=" << to_string(a) << " k=" << k << '\n';);
19241930
if (k == 0 || is_zero(a))
19251931
return;
19261932
if (is_small(a)) {
1927-
set(a, k < 64 ? (a.value() >> k) : 0);
1933+
if (k >= 64) {
1934+
set(a, 0);
1935+
}
1936+
else if (k == 63) {
1937+
// Only possible non-zero result is for INT64_MIN
1938+
set(a, a.value() == std::numeric_limits<int64_t>::min() ? -1 : 0);
1939+
}
1940+
else {
1941+
set(a, a.value() / int64_t(1ULL << k));
1942+
}
19281943
return;
19291944
}
19301945
#ifndef _MP_GMP

0 commit comments

Comments
 (0)