mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
Fix get_int64 and is_int64 methods in mpz. Fix INT64_MAX constant definition.
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
1ef17cbe67
commit
03c1b24dea
|
@ -1299,9 +1299,9 @@ bool mpz_manager<SYNCH>::is_int64(mpz const & a) const {
|
||||||
if (is_small(a))
|
if (is_small(a))
|
||||||
return true;
|
return true;
|
||||||
#ifndef _MP_GMP
|
#ifndef _MP_GMP
|
||||||
if (!is_uint64(a))
|
if (!is_abs_uint64(a))
|
||||||
return false;
|
return false;
|
||||||
uint64 num = get_uint64(a);
|
uint64 num = big_abs_to_uint64(a);
|
||||||
uint64 msb = static_cast<uint64>(1) << 63;
|
uint64 msb = static_cast<uint64>(1) << 63;
|
||||||
uint64 msb_val = msb & num;
|
uint64 msb_val = msb & num;
|
||||||
if (a.m_val >= 0) {
|
if (a.m_val >= 0) {
|
||||||
|
@ -1327,14 +1327,7 @@ uint64 mpz_manager<SYNCH>::get_uint64(mpz const & a) const {
|
||||||
return static_cast<uint64>(a.m_val);
|
return static_cast<uint64>(a.m_val);
|
||||||
#ifndef _MP_GMP
|
#ifndef _MP_GMP
|
||||||
SASSERT(a.m_ptr->m_size > 0);
|
SASSERT(a.m_ptr->m_size > 0);
|
||||||
if (a.m_ptr->m_size == 1)
|
return big_abs_to_uint64(a);
|
||||||
return digits(a)[0];
|
|
||||||
if (sizeof(digit_t) == sizeof(uint64))
|
|
||||||
// 64-bit machine
|
|
||||||
return digits(a)[0];
|
|
||||||
else
|
|
||||||
// 32-bit machine
|
|
||||||
return ((static_cast<uint64>(digits(a)[1]) << 32) | (static_cast<uint64>(digits(a)[0])));
|
|
||||||
#else
|
#else
|
||||||
// GMP version
|
// GMP version
|
||||||
if (sizeof(uint64) == sizeof(unsigned long)) {
|
if (sizeof(uint64) == sizeof(unsigned long)) {
|
||||||
|
@ -1359,7 +1352,7 @@ int64 mpz_manager<SYNCH>::get_int64(mpz const & a) const {
|
||||||
return static_cast<int64>(a.m_val);
|
return static_cast<int64>(a.m_val);
|
||||||
#ifndef _MP_GMP
|
#ifndef _MP_GMP
|
||||||
SASSERT(is_int64(a));
|
SASSERT(is_int64(a));
|
||||||
uint64 num = get_uint64(a);
|
uint64 num = big_abs_to_uint64(a);
|
||||||
if (a.m_val < 0) {
|
if (a.m_val < 0) {
|
||||||
if (num != 0 && (num << 1) == 0)
|
if (num != 0 && (num << 1) == 0)
|
||||||
return INT64_MIN;
|
return INT64_MIN;
|
||||||
|
|
|
@ -211,6 +211,30 @@ class mpz_manager {
|
||||||
|
|
||||||
static digit_t * digits(mpz const & c) { return c.m_ptr->m_digits; }
|
static digit_t * digits(mpz const & c) { return c.m_ptr->m_digits; }
|
||||||
|
|
||||||
|
// Return true if the absolute value fits in a UINT64
|
||||||
|
static bool is_abs_uint64(mpz const & a) {
|
||||||
|
if (is_small(a))
|
||||||
|
return true;
|
||||||
|
if (sizeof(digit_t) == sizeof(uint64))
|
||||||
|
return size(a) <= 1;
|
||||||
|
else
|
||||||
|
return size(a) <= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CAST the absolute value into a UINT64
|
||||||
|
static uint64 big_abs_to_uint64(mpz const & a) {
|
||||||
|
SASSERT(is_abs_uint64(a));
|
||||||
|
SASSERT(!is_small(a));
|
||||||
|
if (a.m_ptr->m_size == 1)
|
||||||
|
return digits(a)[0];
|
||||||
|
if (sizeof(digit_t) == sizeof(uint64))
|
||||||
|
// 64-bit machine
|
||||||
|
return digits(a)[0];
|
||||||
|
else
|
||||||
|
// 32-bit machine
|
||||||
|
return ((static_cast<uint64>(digits(a)[1]) << 32) | (static_cast<uint64>(digits(a)[0])));
|
||||||
|
}
|
||||||
|
|
||||||
template<int IDX>
|
template<int IDX>
|
||||||
void get_sign_cell(mpz const & a, int & sign, mpz_cell * & cell) {
|
void get_sign_cell(mpz const & a, int & sign, mpz_cell * & cell) {
|
||||||
if (is_small(a)) {
|
if (is_small(a)) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ COMPILE_TIME_ASSERT(sizeof(int64) == 8);
|
||||||
#define INT64_MIN static_cast<int64>(0x8000000000000000ull)
|
#define INT64_MIN static_cast<int64>(0x8000000000000000ull)
|
||||||
#endif
|
#endif
|
||||||
#ifndef INT64_MAX
|
#ifndef INT64_MAX
|
||||||
#define INT64_MAX static_cast<int64>(0x0fffffffffffffffull)
|
#define INT64_MAX static_cast<int64>(0x7fffffffffffffffull)
|
||||||
#endif
|
#endif
|
||||||
#ifndef UINT64_MAX
|
#ifndef UINT64_MAX
|
||||||
#define UINT64_MAX 0xffffffffffffffffull
|
#define UINT64_MAX 0xffffffffffffffffull
|
||||||
|
|
Loading…
Reference in a new issue