3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

Remove int64, uint64 typedefs in favor of int64_t / uint64_t.

This commit is contained in:
Bruce Mitchener 2018-03-31 14:45:04 +07:00
parent 16a2ad9afd
commit 2fa304d8de
80 changed files with 437 additions and 449 deletions

View file

@ -7,7 +7,7 @@ Module Name:
Abstract:
A class for wrapping checked (and unchecked) int64 operations.
A class for wrapping checked (and unchecked) int64_t operations.
Note: the mpfx class defines a more general class of fixed-point operations.
A tradeoff is that it relies on a manager.
This class several of the most common operations from rational, so
@ -29,15 +29,15 @@ Revision History:
template<bool CHECK>
class checked_int64 {
int64 m_value;
int64_t m_value;
typedef checked_int64 ci;
rational r64(int64 i) { return rational(i, rational::i64()); }
rational r64(int64_t i) { return rational(i, rational::i64()); }
public:
checked_int64(): m_value(0) {}
checked_int64(int64 v): m_value(v) {}
checked_int64(int64_t v): m_value(v) {}
checked_int64(checked_int64 const& other) { m_value = other.m_value; }
class overflow_exception : public z3_exception {
@ -57,7 +57,7 @@ public:
static checked_int64 one() { return ci(1); }
static checked_int64 minus_one() { return ci(-1);}
int64 get_int64() const { return m_value; }
int64_t get_int64() const { return m_value; }
checked_int64 abs() const {
if (m_value >= 0) {
@ -117,9 +117,9 @@ public:
checked_int64& operator+=(checked_int64 const& other) {
if (CHECK) {
uint64 x = static_cast<uint64>(m_value);
uint64 y = static_cast<uint64>(other.m_value);
int64 r = static_cast<int64>(x + y);
uint64_t x = static_cast<uint64_t>(m_value);
uint64_t y = static_cast<uint64_t>(other.m_value);
int64_t r = static_cast<int64_t>(x + y);
if (m_value > 0 && other.m_value > 0 && r <= 0) throw overflow_exception();
if (m_value < 0 && other.m_value < 0 && r >= 0) throw overflow_exception();
m_value = r;
@ -132,9 +132,9 @@ public:
checked_int64& operator-=(checked_int64 const& other) {
if (CHECK) {
uint64 x = static_cast<uint64>(m_value);
uint64 y = static_cast<uint64>(other.m_value);
int64 r = static_cast<int64>(x - y);
uint64_t x = static_cast<uint64_t>(m_value);
uint64_t y = static_cast<uint64_t>(other.m_value);
int64_t r = static_cast<int64_t>(x - y);
if (m_value > 0 && other.m_value < 0 && r <= 0) throw overflow_exception();
if (m_value < 0 && other.m_value > 0 && r >= 0) throw overflow_exception();
m_value = r;

View file

@ -75,8 +75,8 @@ public:
static void set(double & a, char const * val) { a = atof(val); }
static void set(double & a, int val) { a = static_cast<double>(val); }
static void set(double & a, unsigned val) { a = static_cast<double>(val); }
static void set(double & a, int64 val) { a = static_cast<double>(val); }
static void set(double & a, uint64 val) { a = static_cast<double>(val); }
static void set(double & a, int64_t val) { a = static_cast<double>(val); }
static void set(double & a, uint64_t val) { a = static_cast<double>(val); }
static void swap(double & a, double & b) { std::swap(a, b); }
bool is_pos(double a) const { return a > m_zero_tolerance; }
bool is_neg(double a) const { return a < m_zero_tolerance; }
@ -93,11 +93,11 @@ public:
}
static unsigned hash(double a) {
return hash_ull(static_cast<uint64>(a));
return hash_ull(static_cast<uint64_t>(a));
}
};
static_assert(sizeof(uint64) == sizeof(double), "");
static_assert(sizeof(uint64_t) == sizeof(double), "");
#endif /* DOUBLE_MANAGER_H_ */

View file

@ -140,8 +140,8 @@ struct size_t_hash {
};
struct uint64_hash {
typedef uint64 data;
unsigned operator()(uint64 x) const { return static_cast<unsigned>(x); }
typedef uint64_t data;
unsigned operator()(uint64_t x) const { return static_cast<unsigned>(x); }
};
struct bool_hash {

View file

@ -91,8 +91,8 @@ hwf_manager::~hwf_manager()
{
}
uint64 RAW(double X) { uint64 tmp; memcpy(&tmp, &(X), sizeof(uint64)); return tmp; }
double DBL(uint64 X) { double tmp; memcpy(&tmp, &(X), sizeof(double)); return tmp; }
uint64_t RAW(double X) { uint64_t tmp; memcpy(&tmp, &(X), sizeof(uint64_t)); return tmp; }
double DBL(uint64_t X) { double tmp; memcpy(&tmp, &(X), sizeof(double)); return tmp; }
void hwf_manager::set(hwf & o, int value) {
o.value = (double) value;
@ -147,7 +147,7 @@ void hwf_manager::set(hwf & o, mpf_rounding_mode rm, mpq const & significand, mp
mpq sig;
m_mpq_manager.set(sig, significand);
int64 exp = m_mpz_manager.get_int64(exponent);
int64_t exp = m_mpz_manager.get_int64(exponent);
if (m_mpq_manager.is_zero(significand))
o.value = 0.0;
@ -160,17 +160,17 @@ void hwf_manager::set(hwf & o, mpf_rounding_mode rm, mpq const & significand, mp
}
hwf s; s.value = m_mpq_manager.get_double(sig);
uint64 r = (RAW(s.value) & 0x800FFFFFFFFFFFFFull) | ((exp + 1023) << 52);
uint64_t r = (RAW(s.value) & 0x800FFFFFFFFFFFFFull) | ((exp + 1023) << 52);
o.value = DBL(r);
}
}
void hwf_manager::set(hwf & o, bool sign, uint64 significand, int exponent) {
void hwf_manager::set(hwf & o, bool sign, uint64_t significand, int exponent) {
// Assumption: this represents (sign * -1) * (significand/2^sbits) * 2^exponent.
SASSERT(significand <= 0x000FFFFFFFFFFFFFull);
SASSERT(-1022 <= exponent && exponent <= 1023);
uint64 raw = (sign?0x8000000000000000ull:0);
raw |= (((uint64)exponent) + 1023) << 52;
uint64_t raw = (sign?0x8000000000000000ull:0);
raw |= (((uint64_t)exponent) + 1023) << 52;
raw |= significand;
memcpy(&o.value, &raw, sizeof(double));
}
@ -428,7 +428,7 @@ void hwf_manager::to_rational(hwf const & x, unsynch_mpq_manager & qm, mpq & o)
}
bool hwf_manager::is_zero(hwf const & x) {
uint64 t = RAW(x.value) & 0x7FFFFFFFFFFFFFFFull;
uint64_t t = RAW(x.value) & 0x7FFFFFFFFFFFFFFFull;
return (t == 0x0ull);
// CMW: I tried, and these are slower:
// return (t != 0x0ull) ? false : true;
@ -483,12 +483,12 @@ bool hwf_manager::is_ninf(hwf const & x) {
}
bool hwf_manager::is_normal(hwf const & x) {
uint64 t = RAW(x.value) & 0x7FF0000000000000ull;
uint64_t t = RAW(x.value) & 0x7FF0000000000000ull;
return (t != 0x0ull && t != 0x7FF0000000000000ull);
}
bool hwf_manager::is_denormal(hwf const & x) {
uint64 t = RAW(x.value);
uint64_t t = RAW(x.value);
return ((t & 0x7FF0000000000000ull) == 0x0 &&
(t & 0x000FFFFFFFFFFFFFull) != 0x0);
}
@ -498,7 +498,7 @@ bool hwf_manager::is_regular(hwf const & x) {
// Note that +-0.0 and denormal numbers have exponent==0; these are regular.
// All normal numbers are also regular. What remains is +-Inf and NaN, they are
// not regular and they are the only numbers that have exponent 7FF.
uint64 e = RAW(x.value) & 0x7FF0000000000000ull; // the exponent
uint64_t e = RAW(x.value) & 0x7FF0000000000000ull; // the exponent
return (e != 0x7FF0000000000000ull);
}
@ -513,15 +513,15 @@ bool hwf_manager::is_int(hwf const & x) {
return false;
else
{
uint64 t = sig(x);
uint64_t t = sig(x);
unsigned shift = 52 - ((unsigned)e);
uint64 mask = (0x1ull << shift) - 1;
uint64_t mask = (0x1ull << shift) - 1;
return (t & mask) == 0;
}
}
void hwf_manager::mk_nzero(hwf & o) {
uint64 raw = 0x8000000000000000ull;
uint64_t raw = 0x8000000000000000ull;
o.value = DBL(raw);
}
@ -537,22 +537,22 @@ void hwf_manager::mk_zero(bool sign, hwf & o) {
}
void hwf_manager::mk_nan(hwf & o) {
uint64 raw = 0x7FF0000000000001ull;
uint64_t raw = 0x7FF0000000000001ull;
o.value = DBL(raw);
}
void hwf_manager::mk_inf(bool sign, hwf & o) {
uint64 raw = (sign) ? 0xFFF0000000000000ull : 0x7FF0000000000000ull;
uint64_t raw = (sign) ? 0xFFF0000000000000ull : 0x7FF0000000000000ull;
o.value = DBL(raw);
}
void hwf_manager::mk_pinf(hwf & o) {
uint64 raw = 0x7FF0000000000000ull;
uint64_t raw = 0x7FF0000000000000ull;
o.value = DBL(raw);
}
void hwf_manager::mk_ninf(hwf & o) {
uint64 raw = 0xFFF0000000000000ull;
uint64_t raw = 0xFFF0000000000000ull;
o.value = DBL(raw);
}

View file

@ -28,8 +28,8 @@ class hwf {
friend class hwf_manager;
double value;
hwf & operator=(hwf const & other) { UNREACHABLE(); return *this; }
uint64 get_raw() const {
uint64 n;
uint64_t get_raw() const {
uint64_t n;
SASSERT(sizeof(n) == sizeof(value));
memcpy(&n, &value, sizeof(value));
return n;
@ -60,7 +60,7 @@ public:
void set(hwf & o, mpf_rounding_mode rm, mpq const & value);
void set(hwf & o, mpf_rounding_mode rm, char const * value);
void set(hwf & o, mpf_rounding_mode rm, mpq const & significand, mpz const & exponent);
void set(hwf & o, bool sign, uint64 significand, int exponent);
void set(hwf & o, bool sign, uint64_t significand, int exponent);
void set(hwf & o, hwf const & x);
// auxiliary methods to make the interface compatible with mpf
@ -128,7 +128,7 @@ public:
return (x.get_raw() & 0x8000000000000000ull) != 0;
}
uint64 sig(hwf const & x) const {
uint64_t sig(hwf const & x) const {
return x.get_raw() & 0x000FFFFFFFFFFFFFull;
}

View file

@ -118,12 +118,12 @@ class inf_eps_rational {
bool is_rational() const { return m_infty.is_zero() && m_r.is_rational(); }
int64 get_int64() const {
int64_t get_int64() const {
SASSERT(is_int64());
return m_r.get_int64();
}
uint64 get_uint64() const {
uint64_t get_uint64() const {
SASSERT(is_uint64());
return m_r.get_uint64();
}

View file

@ -109,12 +109,12 @@ class inf_int_rational {
bool is_rational() const { return m_second == 0; }
int64 get_int64() const {
int64_t get_int64() const {
SASSERT(is_int64());
return m_first.get_int64();
}
uint64 get_uint64() const {
uint64_t get_uint64() const {
SASSERT(is_uint64());
return m_first.get_uint64();
}

View file

@ -122,12 +122,12 @@ class inf_rational {
bool is_rational() const { return m_second.is_zero(); }
int64 get_int64() const {
int64_t get_int64() const {
SASSERT(is_int64());
return m_first.get_int64();
}
uint64 get_uint64() const {
uint64_t get_uint64() const {
SASSERT(is_uint64());
return m_first.get_uint64();
}

View file

@ -60,8 +60,8 @@ class inf_s_integer {
bool is_int64() const { return m_second == 0; }
bool is_uint64() const { return m_second == 0; }
bool is_rational() const { return m_second == 0; }
int64 get_int64() const { return m_first; }
uint64 get_uint64() const { return m_first; }
int64_t get_int64() const { return m_first; }
uint64_t get_uint64() const { return m_first; }
s_integer get_rational() const { return s_integer(m_first); }
s_integer get_infinitesimal() const { return s_integer(m_second); }
inf_s_integer & operator=(const inf_s_integer & r) {

View file

@ -250,7 +250,7 @@ void mpbq_manager::mul(mpbq const & a, mpz const & b, mpbq & r) {
}
void mpbq_manager::power(mpbq & a, unsigned k) {
SASSERT(static_cast<uint64>(k) * static_cast<uint64>(a.k()) <= static_cast<uint64>(UINT_MAX));
SASSERT(static_cast<uint64_t>(k) * static_cast<uint64_t>(a.k()) <= static_cast<uint64_t>(UINT_MAX));
// We don't need to normalize because:
// If a.m_k == 0, then a is an integer, and the result be an integer
// If a.m_k > 0, then a.m_num must be odd, and the (a.m_num)^k will also be odd

View file

@ -84,7 +84,7 @@ public:
void set(mpbq & a, mpz const & n, unsigned k) { m_manager.set(a.m_num, n); a.m_k = k; normalize(a); }
void set(mpbq & a, mpz const & n) { m_manager.set(a.m_num, n); a.m_k = 0; }
void set(mpbq & a, mpbq const & b) { m_manager.set(a.m_num, b.m_num); a.m_k = b.m_k; }
void set(mpbq & a, int64 n, unsigned k) { m_manager.set(a.m_num, n); a.m_k = k; normalize(a); }
void set(mpbq & a, int64_t n, unsigned k) { m_manager.set(a.m_num, n); a.m_k = k; normalize(a); }
bool is_int(mpbq const & a) const { return a.m_k == 0; }
void get_numerator(mpbq const & a, mpz & n) { m_manager.set(n, a.m_num); }

View file

@ -115,11 +115,11 @@ void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, double value) {
// double === mpf(11, 53)
static_assert(sizeof(double) == 8, "doubles are 8 bytes");
uint64 raw;
uint64_t raw;
memcpy(&raw, &value, sizeof(double));
bool sign = (raw >> 63) != 0;
int64 e = ((raw & 0x7FF0000000000000ull) >> 52) - 1023;
uint64 s = raw & 0x000FFFFFFFFFFFFFull;
int64_t e = ((raw & 0x7FF0000000000000ull) >> 52) - 1023;
uint64_t s = raw & 0x000FFFFFFFFFFFFFull;
TRACE("mpf_dbg", tout << "set: " << value << " is: raw=" << raw << " (double)" <<
" sign=" << sign << " s=" << s << " e=" << e << std::endl;);
@ -300,7 +300,7 @@ void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, mpf_rounding_mode
TRACE("mpf_dbg", tout << "set: res = " << to_string(o) << std::endl;);
}
void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, bool sign, mpf_exp_t exponent, uint64 significand) {
void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, bool sign, mpf_exp_t exponent, uint64_t significand) {
// Assumption: this represents (sign * -1) * (significand/2^sbits) * 2^exponent.
o.ebits = ebits;
o.sbits = sbits;
@ -1711,8 +1711,8 @@ void mpf_manager::to_rational(mpf const & x, unsynch_mpq_manager & qm, mpq & o)
double mpf_manager::to_double(mpf const & x) {
SASSERT(x.ebits <= 11 && x.sbits <= 53);
uint64 raw = 0;
int64 sig = 0, exp = 0;
uint64_t raw = 0;
int64_t sig = 0, exp = 0;
sig = m_mpz_manager.get_uint64(x.significand);
sig <<= 53 - x.sbits;
@ -1741,7 +1741,7 @@ float mpf_manager::to_float(mpf const & x) {
unsigned int raw = 0;
unsigned int sig = 0, exp = 0;
uint64 q = m_mpz_manager.get_uint64(x.significand);
uint64_t q = m_mpz_manager.get_uint64(x.significand);
SASSERT(q < 4294967296ull);
sig = q & 0x00000000FFFFFFFF;
sig <<= 24 - x.sbits;
@ -1751,7 +1751,7 @@ float mpf_manager::to_float(mpf const & x) {
else if (has_bot_exp(x))
exp = -127;
else {
int64 q = x.exponent;
int64_t q = x.exponent;
SASSERT(q < 4294967296ll);
exp = q & 0x00000000FFFFFFFF;
}

View file

@ -35,7 +35,7 @@ typedef enum {
MPF_ROUND_TOWARD_ZERO
} mpf_rounding_mode;
typedef int64 mpf_exp_t;
typedef int64_t mpf_exp_t;
class mpf {
friend class mpf_manager;
@ -80,7 +80,7 @@ public:
void set(mpf & o, unsigned ebits, unsigned sbits, mpf_rounding_mode rm, mpq const & value);
void set(mpf & o, unsigned ebits, unsigned sbits, mpf_rounding_mode rm, char const * value);
void set(mpf & o, unsigned ebits, unsigned sbits, mpf_rounding_mode rm, mpz const & exponent, mpq const & significand);
void set(mpf & o, unsigned ebits, unsigned sbits, bool sign, mpf_exp_t exponent, uint64 significand);
void set(mpf & o, unsigned ebits, unsigned sbits, bool sign, mpf_exp_t exponent, uint64_t significand);
void set(mpf & o, unsigned ebits, unsigned sbits, bool sign, mpf_exp_t exponent, mpz const & significand);
void set(mpf & o, mpf const & x);
void set(mpf & o, unsigned ebits, unsigned sbits, mpf_rounding_mode rm, mpf const & x);

View file

@ -155,27 +155,27 @@ bool mpff_manager::is_uint64(mpff const & n) const {
!has_one_at_first_k_bits(m_precision, sig(n), -n.m_exponent);
}
uint64 mpff_manager::get_uint64(mpff const & a) const {
uint64_t mpff_manager::get_uint64(mpff const & a) const {
SASSERT(is_uint64(a));
if (is_zero(a)) return 0;
int exp = -a.m_exponent - sizeof(unsigned) * 8 * (m_precision - 2);
SASSERT(exp >= 0);
uint64 * s = reinterpret_cast<uint64*>(sig(a) + (m_precision - 2));
uint64_t * s = reinterpret_cast<uint64_t*>(sig(a) + (m_precision - 2));
return *s >> exp;
}
int64 mpff_manager::get_int64(mpff const & a) const {
int64_t mpff_manager::get_int64(mpff const & a) const {
SASSERT(is_int64(a));
if (is_zero(a)) return 0;
int exp = -a.m_exponent - sizeof(unsigned) * 8 * (m_precision - 2);
SASSERT(exp >= 0);
uint64 * s = reinterpret_cast<uint64*>(sig(a) + (m_precision - 2));
uint64_t * s = reinterpret_cast<uint64_t*>(sig(a) + (m_precision - 2));
// INT64_MIN case
if (exp == 0 && *s == 0x8000000000000000ull && is_neg(a)) {
return INT64_MIN;
}
else {
int64 r = *s >> exp;
int64_t r = *s >> exp;
if (is_neg(a))
r = -r;
return r;
@ -249,26 +249,26 @@ void mpff_manager::set(mpff & n, unsigned v) {
SASSERT(check(n));
}
void mpff_manager::set(mpff & n, int64 v) {
void mpff_manager::set(mpff & n, int64_t v) {
if (v == 0) {
reset(n);
}
else {
if (v < 0) {
set(n, 1 + static_cast<uint64>(-(1+v)));
set(n, 1 + static_cast<uint64_t>(-(1+v)));
n.m_sign = 1;
}
else {
set(n, static_cast<uint64>(v));
set(n, static_cast<uint64_t>(v));
}
}
SASSERT(check(n));
SASSERT(get_int64(n) == v);
}
void mpff_manager::set(mpff & n, uint64 v) {
void mpff_manager::set(mpff & n, uint64_t v) {
#ifdef Z3DEBUG
uint64 old_v = v;
uint64_t old_v = v;
#endif
if (v == 0) {
reset(n);
@ -278,7 +278,7 @@ void mpff_manager::set(mpff & n, uint64 v) {
n.m_sign = 0;
unsigned * _v = reinterpret_cast<unsigned*>(&v);
int num_leading_zeros = nlz(2, _v);
n.m_exponent = static_cast<int>(8 * sizeof(uint64)) - num_leading_zeros - static_cast<int>(m_precision_bits);
n.m_exponent = static_cast<int>(8 * sizeof(uint64_t)) - num_leading_zeros - static_cast<int>(m_precision_bits);
v <<= num_leading_zeros;
SASSERT(m_precision >= 2);
unsigned * s = sig(n);
@ -299,7 +299,7 @@ void mpff_manager::set(mpff & n, int num, unsigned den) {
SASSERT(check(n));
}
void mpff_manager::set(mpff & n, int64 num, uint64 den) {
void mpff_manager::set(mpff & n, int64_t num, uint64_t den) {
scoped_mpff a(*this), b(*this);
set(a, num);
set(b, den);
@ -470,7 +470,7 @@ bool mpff_manager::lt(mpff const & a, mpff const & b) const {
}
}
void mpff_manager::inc_significand(unsigned * s, int64 & exp) {
void mpff_manager::inc_significand(unsigned * s, int64_t & exp) {
if (!::inc(m_precision, s)) {
SASSERT(::is_zero(m_precision, s));
s[m_precision - 1] = MIN_MSW;
@ -597,7 +597,7 @@ void mpff_manager::prev(mpff & a) {
SASSERT(check(a));
}
void mpff_manager::set_big_exponent(mpff & a, int64 e) {
void mpff_manager::set_big_exponent(mpff & a, int64_t e) {
SASSERT(e > INT_MAX || e < INT_MIN);
if (e > INT_MAX) {
if (a.m_sign == 1) {
@ -715,7 +715,7 @@ void mpff_manager::add_sub(bool is_sub, mpff const & a, mpff const & b, mpff & c
else if (num_leading_zeros == sizeof(unsigned) * 8 - 1) {
// shift 1 right
bool _inc_significand = ((c.m_sign == 1) != m_to_plus_inf) && has_one_at_first_k_bits(m_precision*2, sig_r, 1);
int64 exp_c = exp_a;
int64_t exp_c = exp_a;
exp_c++;
shr(m_precision + 1, sig_r, 1, m_precision, sig_c);
if (_inc_significand)
@ -728,7 +728,7 @@ void mpff_manager::add_sub(bool is_sub, mpff const & a, mpff const & b, mpff & c
// Now, we can assume sig_r has size m_precision
SASSERT(num_leading_zeros > 0);
// shift left num_leading_zeros
int64 exp_c = exp_a;
int64_t exp_c = exp_a;
exp_c -= num_leading_zeros;
shl(m_precision, sig_r, num_leading_zeros, m_precision, sig_c);
set_exponent(c, exp_c);
@ -752,7 +752,7 @@ void mpff_manager::add_sub(bool is_sub, mpff const & a, mpff const & b, mpff & c
reset(c);
}
else if (num_leading_zeros > 0) {
int64 exp_c = exp_a;
int64_t exp_c = exp_a;
exp_c -= num_leading_zeros;
shl(m_precision, sig_c, num_leading_zeros, m_precision, sig_c);
set_exponent(c, exp_c);
@ -787,10 +787,10 @@ void mpff_manager::mul(mpff const & a, mpff const & b, mpff & c) {
allocate_if_needed(c);
TRACE("mpff", tout << "mul("; display(tout, a); tout << ", "; display(tout, b); tout << ")\n";);
c.m_sign = a.m_sign ^ b.m_sign;
// use int64 to make sure we do not have overflows
int64 exp_a = a.m_exponent;
int64 exp_b = b.m_exponent;
int64 exp_c = exp_a + exp_b;
// use int64_t to make sure we do not have overflows
int64_t exp_a = a.m_exponent;
int64_t exp_b = b.m_exponent;
int64_t exp_c = exp_a + exp_b;
// store result in m_buffers[0]
unsigned * r = m_buffers[0].c_ptr();
m_mpn_manager.mul(sig(a), m_precision, sig(b), m_precision, r);
@ -834,7 +834,7 @@ void mpff_manager::div(mpff const & a, mpff const & b, mpff & c) {
#if 1
else if (is_two(b)) {
set(c, a);
int64 exp_c = a.m_exponent;
int64_t exp_c = a.m_exponent;
exp_c--;
set_exponent(c, exp_c);
}
@ -842,10 +842,10 @@ void mpff_manager::div(mpff const & a, mpff const & b, mpff & c) {
else {
allocate_if_needed(c);
c.m_sign = a.m_sign ^ b.m_sign;
// use int64 to make sure we do not have overflows
int64 exp_a = a.m_exponent;
int64 exp_b = b.m_exponent;
int64 exp_c = exp_a - exp_b;
// use int64_t to make sure we do not have overflows
int64_t exp_a = a.m_exponent;
int64_t exp_b = b.m_exponent;
int64_t exp_c = exp_a - exp_b;
exp_c -= m_precision_bits; // we will multiplying (shifting) a by 2^m_precision_bits.
// copy a to buffer 0, and shift by m_precision_bits
@ -1023,7 +1023,7 @@ void mpff_manager::power(mpff const & a, unsigned p, mpff & b) {
b.m_sign = 0;
else
b.m_sign = a.m_sign;
int64 exp = a.m_exponent;
int64_t exp = a.m_exponent;
exp *= p;
if (exp > INT_MAX || exp < INT_MIN)
throw overflow_exception();
@ -1057,7 +1057,7 @@ void mpff_manager::power(mpff const & a, unsigned p, mpff & b) {
bool mpff_manager::is_power_of_two(mpff const & a, unsigned & k) const {
if (!is_power_of_two(a))
return false;
int64 exp = a.m_exponent + m_precision_bits - 1;
int64_t exp = a.m_exponent + m_precision_bits - 1;
SASSERT(exp >= 0);
k = static_cast<unsigned>(exp);
return true;
@ -1132,7 +1132,7 @@ void mpff_manager::to_mpq_core(mpff const & n, mpq_manager<SYNCH> & m, mpq & t)
if (exp < 0) {
// Avoid -INT_MIN == INT_MIN issue. It is not really useful, since we will run out of memory anyway.
if (exp == INT_MIN)
abs_exp = static_cast<unsigned>(-static_cast<int64>(INT_MIN));
abs_exp = static_cast<unsigned>(-static_cast<int64_t>(INT_MIN));
else
abs_exp = -exp;
}
@ -1177,7 +1177,7 @@ void mpff_manager::display(std::ostream & out, mpff const & n) const {
svector<unsigned> & u_buffer = const_cast<mpff_manager*>(this)->m_buffers[0];
int num_trailing_zeros = ntz(m_precision, u_buffer.c_ptr());
int shift = 0;
int64 exp = n.m_exponent; // use int64 to avoid -INT_MIN == INT_MIN issue
int64_t exp = n.m_exponent; // use int64_t to avoid -INT_MIN == INT_MIN issue
if (exp < 0) {
if (num_trailing_zeros >= -exp) {
shift = static_cast<int>(-exp);
@ -1194,7 +1194,7 @@ void mpff_manager::display(std::ostream & out, mpff const & n) const {
out << m_mpn_manager.to_string(u_buffer.c_ptr(), m_precision, str_buffer.begin(), str_buffer.size());
if (exp > 0) {
if (exp <= 63) {
uint64 _exp = 1;
uint64_t _exp = 1;
_exp <<= exp;
out << "*" << _exp;
}
@ -1209,7 +1209,7 @@ void mpff_manager::display(std::ostream & out, mpff const & n) const {
else if (exp < 0) {
exp = -exp;
if (exp <= 63) {
uint64 _exp = 1;
uint64_t _exp = 1;
_exp <<= exp;
out << "/" << _exp;
}
@ -1225,8 +1225,8 @@ void mpff_manager::display(std::ostream & out, mpff const & n) const {
void mpff_manager::display_decimal(std::ostream & out, mpff const & n, unsigned prec, unsigned min_exponent) {
// The result in scientific notation when n.m_exponent >= min_exponent or n.m_exponent <= - min_exponent - m_precision_bits
int64 exp = n.m_exponent;
if (exp >= min_exponent || exp <= -static_cast<int64>(min_exponent) - m_precision_bits || is_int(n)) {
int64_t exp = n.m_exponent;
if (exp >= min_exponent || exp <= -static_cast<int64_t>(min_exponent) - m_precision_bits || is_int(n)) {
display(out, n);
return;
}
@ -1327,7 +1327,7 @@ void mpff_manager::display_smt2(std::ostream & out, mpff const & n, bool decimal
svector<unsigned> & u_buffer = const_cast<mpff_manager*>(this)->m_buffers[0];
int num_trailing_zeros = ntz(m_precision, u_buffer.c_ptr());
int shift = 0;
int64 exp = n.m_exponent;
int64_t exp = n.m_exponent;
if (exp < 0) {
if (num_trailing_zeros >= -exp) {
shift = static_cast<int>(-exp);
@ -1353,7 +1353,7 @@ void mpff_manager::display_smt2(std::ostream & out, mpff const & n, bool decimal
if (exp != 0) {
if (exp < 0) exp = -exp;
if (exp <= 63) {
uint64 _exp = 1;
uint64_t _exp = 1;
_exp <<= exp;
out << _exp;
if (decimal) out << ".0";
@ -1387,8 +1387,8 @@ unsigned mpff_manager::prev_power_of_two(mpff const & a) {
return 0;
if (a.m_exponent <= -static_cast<int>(m_precision_bits))
return 0; // Number is smaller than 1
SASSERT(static_cast<int64>(a.m_exponent) + static_cast<int64>(m_precision_bits) - 1 >= 0);
SASSERT(static_cast<int64>(a.m_exponent) + static_cast<int64>(m_precision_bits) - 1 <= static_cast<int64>(static_cast<uint64>(UINT_MAX)));
SASSERT(static_cast<int64_t>(a.m_exponent) + static_cast<int64_t>(m_precision_bits) - 1 >= 0);
SASSERT(static_cast<int64_t>(a.m_exponent) + static_cast<int64_t>(m_precision_bits) - 1 <= static_cast<int64_t>(static_cast<uint64_t>(UINT_MAX)));
return m_precision_bits + a.m_exponent - 1;
}

View file

@ -92,7 +92,7 @@ class mpff_manager {
//
// Remarks:
//
// - All values of type int, unsigned, int64 and uint64 can be precisely represented as mpff numerals.
// - All values of type int, unsigned, int64_t and uint64_t can be precisely represented as mpff numerals.
//
// - Hardware float and double values (corresponding to rationals) can also be precisely represented as mpff numerals.
// That is, NaN, +oo and -oo are not supported by this module.
@ -141,14 +141,14 @@ class mpff_manager {
// copy (and shift by m_precision_bits) n to buffer idx
void to_buffer_shifting(unsigned idx, mpff const & n) const;
void inc_significand(unsigned * s, int64 & exp);
void inc_significand(unsigned * s, int64_t & exp);
void inc_significand(mpff & a);
void dec_significand(mpff & a);
bool min_significand(mpff const & a) const;
void set_min_significand(mpff & a);
void set_max_significand(mpff & a);
void set_big_exponent(mpff & a, int64 e);
void set_exponent(mpff & a, int64 e) {
void set_big_exponent(mpff & a, int64_t e);
void set_exponent(mpff & a, int64_t e) {
if (e > INT_MAX || e < INT_MIN)
set_big_exponent(a, e);
else
@ -286,12 +286,12 @@ public:
bool is_plus_epsilon(mpff const & a) const;
/**
\brief Return true if \c a is an integer and fits in an int64 machine integer.
\brief Return true if \c a is an integer and fits in an int64_t machine integer.
*/
bool is_int64(mpff const & a) const;
/**
\brief Return true if \c a is a non-negative integer and fits in an int64 machine integer.
\brief Return true if \c a is a non-negative integer and fits in an int64_t machine integer.
*/
bool is_uint64(mpff const & a) const;
@ -372,10 +372,10 @@ public:
void set(mpff & n, int v);
void set(mpff & n, unsigned v);
void set(mpff & n, int64 v);
void set(mpff & n, uint64 v);
void set(mpff & n, int64_t v);
void set(mpff & n, uint64_t v);
void set(mpff & n, int num, unsigned den);
void set(mpff & n, int64 num, uint64 den);
void set(mpff & n, int64_t num, uint64_t den);
void set(mpff & n, mpff const & v);
void set(mpff & n, unsynch_mpz_manager & m, mpz const & v);
void set(mpff & n, synch_mpz_manager & m, mpz const & v);
@ -448,14 +448,14 @@ public:
\pre is_int64(n)
*/
int64 get_int64(mpff const & n) const;
int64_t get_int64(mpff const & n) const;
/**
\brief Return n as an uint64.
\pre is_uint64(n)
*/
uint64 get_uint64(mpff const & n) const;
uint64_t get_uint64(mpff const & n) const;
/**
\brief Return the biggest k s.t. 2^k <= a.

View file

@ -164,10 +164,10 @@ void mpfx_manager::set(mpfx & n, unsigned v) {
SASSERT(check(n));
}
void mpfx_manager::set(mpfx & n, int64 v) {
void mpfx_manager::set(mpfx & n, int64_t v) {
if (m_int_part_sz == 1) {
if (v < -static_cast<int64>(static_cast<uint64>(UINT_MAX)) ||
v > static_cast<int64>(static_cast<uint64>(UINT_MAX)))
if (v < -static_cast<int64_t>(static_cast<uint64_t>(UINT_MAX)) ||
v > static_cast<int64_t>(static_cast<uint64_t>(UINT_MAX)))
throw overflow_exception();
}
if (v == 0) {
@ -175,11 +175,11 @@ void mpfx_manager::set(mpfx & n, int64 v) {
}
else {
if (v < 0) {
set(n, static_cast<uint64>(-v));
set(n, static_cast<uint64_t>(-v));
n.m_sign = 1;
}
else {
set(n, static_cast<uint64>(v));
set(n, static_cast<uint64_t>(v));
}
}
SASSERT(is_int(n));
@ -187,9 +187,9 @@ void mpfx_manager::set(mpfx & n, int64 v) {
SASSERT(check(n));
}
void mpfx_manager::set(mpfx & n, uint64 v) {
void mpfx_manager::set(mpfx & n, uint64_t v) {
if (m_int_part_sz == 1) {
if (v > static_cast<uint64>(UINT_MAX))
if (v > static_cast<uint64_t>(UINT_MAX))
throw overflow_exception();
}
@ -200,7 +200,7 @@ void mpfx_manager::set(mpfx & n, uint64 v) {
allocate_if_needed(n);
n.m_sign = 0;
unsigned * w = words(n);
uint64 * _vp = &v;
uint64_t * _vp = &v;
unsigned * _v = nullptr;
memcpy(&_v, &_vp, sizeof(unsigned*));
for (unsigned i = 0; i < m_total_sz; i++)
@ -226,7 +226,7 @@ void mpfx_manager::set(mpfx & n, int num, unsigned den) {
SASSERT(check(n));
}
void mpfx_manager::set(mpfx & n, int64 num, uint64 den) {
void mpfx_manager::set(mpfx & n, int64_t num, uint64_t den) {
scoped_mpfx a(*this), b(*this);
set(a, num);
set(b, den);
@ -677,27 +677,27 @@ bool mpfx_manager::is_power_of_two(mpfx const & a) const {
return is_power_of_two(a, k);
}
int64 mpfx_manager::get_int64(mpfx const & n) const {
int64_t mpfx_manager::get_int64(mpfx const & n) const {
SASSERT(is_int64(n));
unsigned * w = words(n);
w += m_frac_part_sz;
uint64 r = 0;
memcpy(&r, w, sizeof(uint64));
uint64_t r = 0;
memcpy(&r, w, sizeof(uint64_t));
if (r == 0x8000000000000000ull) {
SASSERT(is_neg(n));
return INT64_MIN;
}
else {
return is_neg(n) ? -static_cast<int64>(r) : r;
return is_neg(n) ? -static_cast<int64_t>(r) : r;
}
}
uint64 mpfx_manager::get_uint64(mpfx const & n) const {
uint64_t mpfx_manager::get_uint64(mpfx const & n) const {
SASSERT(is_uint64(n));
unsigned * w = words(n);
w += m_frac_part_sz;
uint64 r = 0;
memcpy(&r, w, sizeof(uint64));
uint64_t r = 0;
memcpy(&r, w, sizeof(uint64_t));
return r;
}

View file

@ -200,12 +200,12 @@ public:
bool is_minus_one(mpfx const & n) const { return is_neg(n) && is_abs_one(n); }
/**
\brief Return true if \c a is an integer and fits in an int64 machine integer.
\brief Return true if \c a is an integer and fits in an \c int64_t machine integer.
*/
bool is_int64(mpfx const & a) const;
/**
\brief Return true if \c a is a non-negative integer and fits in an int64 machine integer.
\brief Return true if \c a is a non-negative integer and fits in an \c int64_t machine integer.
*/
bool is_uint64(mpfx const & a) const;
@ -306,10 +306,10 @@ public:
void set(mpfx & n, int v);
void set(mpfx & n, unsigned v);
void set(mpfx & n, int64 v);
void set(mpfx & n, uint64 v);
void set(mpfx & n, int64_t v);
void set(mpfx & n, uint64_t v);
void set(mpfx & n, int num, unsigned den);
void set(mpfx & n, int64 num, uint64 den);
void set(mpfx & n, int64_t num, uint64_t den);
void set(mpfx & n, mpfx const & v);
void set(mpfx & n, unsynch_mpz_manager & m, mpz const & v);
void set(mpfx & n, synch_mpz_manager & m, mpz const & v);
@ -343,14 +343,14 @@ public:
\pre is_int64(n)
*/
int64 get_int64(mpfx const & n) const;
int64_t get_int64(mpfx const & n) const;
/**
\brief Return n as an uint64.
\pre is_uint64(n)
*/
uint64 get_uint64(mpfx const & n) const;
uint64_t get_uint64(mpfx const & n) const;
/**
\brief Convert n into a mpz numeral.

View file

@ -23,7 +23,7 @@ Revision History:
#define max(a,b) (((a) > (b)) ? (a) : (b))
typedef uint64 mpn_double_digit;
typedef uint64_t mpn_double_digit;
static_assert(sizeof(mpn_double_digit) == 2 * sizeof(mpn_digit), "size alignment");
const mpn_digit mpn_manager::zero = 0;

View file

@ -686,7 +686,7 @@ public:
normalize(a);
}
void set(mpq & a, int64 n, uint64 d) {
void set(mpq & a, int64_t n, uint64_t d) {
SASSERT(d != 0);
set(a.m_num, n);
set(a.m_den, d);
@ -718,16 +718,16 @@ public:
void set(mpq & a, char const * val);
void set(mpz & a, int64 val) { mpz_manager<SYNCH>::set(a, val); }
void set(mpz & a, int64_t val) { mpz_manager<SYNCH>::set(a, val); }
void set(mpq & a, int64 val) {
void set(mpq & a, int64_t val) {
set(a.m_num, val);
reset_denominator(a);
}
void set(mpz & a, uint64 val) { mpz_manager<SYNCH>::set(a, val); }
void set(mpz & a, uint64_t val) { mpz_manager<SYNCH>::set(a, val); }
void set(mpq & a, uint64 val) {
void set(mpq & a, uint64_t val) {
set(a.m_num, val);
reset_denominator(a);
}
@ -765,17 +765,17 @@ public:
bool is_int64(mpz const & a) const { return mpz_manager<SYNCH>::is_int64(a); }
uint64 get_uint64(mpz const & a) const { return mpz_manager<SYNCH>::get_uint64(a); }
uint64_t get_uint64(mpz const & a) const { return mpz_manager<SYNCH>::get_uint64(a); }
int64 get_int64(mpz const & a) const { return mpz_manager<SYNCH>::get_int64(a); }
int64_t get_int64(mpz const & a) const { return mpz_manager<SYNCH>::get_int64(a); }
bool is_uint64(mpq const & a) const { return is_int(a) && is_uint64(a.m_num); }
bool is_int64(mpq const & a) const { return is_int(a) && is_int64(a.m_num); }
uint64 get_uint64(mpq const & a) const { SASSERT(is_uint64(a)); return get_uint64(a.m_num); }
uint64_t get_uint64(mpq const & a) const { SASSERT(is_uint64(a)); return get_uint64(a.m_num); }
int64 get_int64(mpq const & a) const { SASSERT(is_int64(a)); return get_int64(a.m_num); }
int64_t get_int64(mpq const & a) const { SASSERT(is_int64(a)); return get_int64(a.m_num); }
double get_double(mpz const & a) const { return mpz_manager<SYNCH>::get_double(a); }

View file

@ -81,7 +81,7 @@ static T gcd_core(T u, T v) {
}
unsigned u_gcd(unsigned u, unsigned v) { return gcd_core(u, v); }
uint64 u64_gcd(uint64 u, uint64 v) { return gcd_core(u, v); }
uint64_t u64_gcd(uint64_t u, uint64_t v) { return gcd_core(u, v); }
template<bool SYNCH>
mpz_manager<SYNCH>::mpz_manager():
@ -89,7 +89,7 @@ mpz_manager<SYNCH>::mpz_manager():
if (SYNCH)
omp_init_nest_lock(&m_lock);
#ifndef _MP_GMP
if (sizeof(digit_t) == sizeof(uint64)) {
if (sizeof(digit_t) == sizeof(uint64_t)) {
// 64-bit machine
m_init_cell_capacity = 4;
}
@ -101,7 +101,7 @@ mpz_manager<SYNCH>::mpz_manager():
m_arg[i] = allocate(m_init_cell_capacity);
m_arg[i]->m_size = 1;
}
set(m_int_min, -static_cast<int64>(INT_MIN));
set(m_int_min, -static_cast<int64_t>(INT_MIN));
#else
// GMP
mpz_init(m_tmp);
@ -122,8 +122,8 @@ mpz_manager<SYNCH>::mpz_manager():
mpz_init(m_int64_max);
mpz_init(m_int64_min);
max_l = static_cast<unsigned>(INT64_MAX % static_cast<int64>(UINT_MAX));
max_h = static_cast<unsigned>(INT64_MAX / static_cast<int64>(UINT_MAX));
max_l = static_cast<unsigned>(INT64_MAX % static_cast<int64_t>(UINT_MAX));
max_h = static_cast<unsigned>(INT64_MAX / static_cast<int64_t>(UINT_MAX));
mpz_set_ui(m_int64_max, max_h);
mpz_set_ui(m_tmp, UINT_MAX);
mpz_mul(m_int64_max, m_tmp, m_int64_max);
@ -134,7 +134,7 @@ mpz_manager<SYNCH>::mpz_manager():
#endif
mpz one(1);
set(m_two64, (uint64)UINT64_MAX);
set(m_two64, (uint64_t)UINT64_MAX);
add(m_two64, one, m_two64);
}
@ -162,13 +162,13 @@ mpz_manager<SYNCH>::~mpz_manager() {
}
template<bool SYNCH>
void mpz_manager<SYNCH>::set_big_i64(mpz & c, int64 v) {
void mpz_manager<SYNCH>::set_big_i64(mpz & c, int64_t v) {
#ifndef _MP_GMP
if (is_small(c)) {
c.m_ptr = allocate(m_init_cell_capacity);
}
SASSERT(capacity(c) >= m_init_cell_capacity);
uint64 _v;
uint64_t _v;
if (v < 0) {
_v = -v;
c.m_val = -1;
@ -177,7 +177,7 @@ void mpz_manager<SYNCH>::set_big_i64(mpz & c, int64 v) {
_v = v;
c.m_val = 1;
}
if (sizeof(digit_t) == sizeof(uint64)) {
if (sizeof(digit_t) == sizeof(uint64_t)) {
// 64-bit machine
digits(c)[0] = static_cast<digit_t>(_v);
c.m_ptr->m_size = 1;
@ -192,7 +192,7 @@ void mpz_manager<SYNCH>::set_big_i64(mpz & c, int64 v) {
if (is_small(c)) {
c.m_ptr = allocate();
}
uint64 _v;
uint64_t _v;
bool sign;
if (v < 0) {
_v = -v;
@ -212,14 +212,14 @@ void mpz_manager<SYNCH>::set_big_i64(mpz & c, int64 v) {
}
template<bool SYNCH>
void mpz_manager<SYNCH>::set_big_ui64(mpz & c, uint64 v) {
void mpz_manager<SYNCH>::set_big_ui64(mpz & c, uint64_t v) {
#ifndef _MP_GMP
if (is_small(c)) {
c.m_ptr = allocate(m_init_cell_capacity);
}
SASSERT(capacity(c) >= m_init_cell_capacity);
c.m_val = 1;
if (sizeof(digit_t) == sizeof(uint64)) {
if (sizeof(digit_t) == sizeof(uint64_t)) {
// 64-bit machine
digits(c)[0] = static_cast<digit_t>(v);
c.m_ptr->m_size = 1;
@ -726,7 +726,7 @@ void mpz_manager<SYNCH>::gcd(mpz const & a, mpz const & b, mpz & c) {
// For now, it only works if sizeof(digit_t) == sizeof(unsigned)
static_assert(sizeof(digit_t) == sizeof(unsigned), "");
int64 a_hat, b_hat, A, B, C, D, T, q, a_sz, b_sz;
int64_t a_hat, b_hat, A, B, C, D, T, q, a_sz, b_sz;
mpz a1, b1, t, r, tmp;
set(a1, a);
set(b1, b);
@ -766,10 +766,10 @@ void mpz_manager<SYNCH>::gcd(mpz const & a, mpz const & b, mpz & c) {
D = 1;
while (true) {
// Loop invariants
SASSERT(a_hat + A <= static_cast<int64>(UINT_MAX) + 1);
SASSERT(a_hat + B < static_cast<int64>(UINT_MAX) + 1);
SASSERT(b_hat + C < static_cast<int64>(UINT_MAX) + 1);
SASSERT(b_hat + D <= static_cast<int64>(UINT_MAX) + 1);
SASSERT(a_hat + A <= static_cast<int64_t>(UINT_MAX) + 1);
SASSERT(a_hat + B < static_cast<int64_t>(UINT_MAX) + 1);
SASSERT(b_hat + C < static_cast<int64_t>(UINT_MAX) + 1);
SASSERT(b_hat + D <= static_cast<int64_t>(UINT_MAX) + 1);
// overflows can't happen since I'm using int64
if (b_hat + C == 0 || b_hat + D == 0)
break;
@ -1035,7 +1035,7 @@ void mpz_manager<SYNCH>::bitwise_or(mpz const & a, mpz const & b, mpz & c) {
mod(a1, m_two64, a2);
mod(b1, m_two64, b2);
TRACE("mpz", tout << "a2: " << to_string(a2) << ", b2: " << to_string(b2) << "\n";);
uint64 v = get_uint64(a2) | get_uint64(b2);
uint64_t v = get_uint64(a2) | get_uint64(b2);
TRACE("mpz", tout << "uint(a2): " << get_uint64(a2) << ", uint(b2): " << get_uint64(b2) << "\n";);
set(tmp, v);
mul(tmp, m, tmp);
@ -1082,7 +1082,7 @@ void mpz_manager<SYNCH>::bitwise_and(mpz const & a, mpz const & b, mpz & c) {
while (!is_zero(a1) && !is_zero(b1)) {
mod(a1, m_two64, a2);
mod(b1, m_two64, b2);
uint64 v = get_uint64(a2) & get_uint64(b2);
uint64_t v = get_uint64(a2) & get_uint64(b2);
set(tmp, v);
mul(tmp, m, tmp);
add(c, tmp, c); // c += m * v
@ -1119,7 +1119,7 @@ void mpz_manager<SYNCH>::bitwise_xor(mpz const & a, mpz const & b, mpz & c) {
while (!is_zero(a1) && !is_zero(b1)) {
mod(a1, m_two64, a2);
mod(b1, m_two64, b2);
uint64 v = get_uint64(a2) ^ get_uint64(b2);
uint64_t v = get_uint64(a2) ^ get_uint64(b2);
set(tmp, v);
mul(tmp, m, tmp);
add(c, tmp, c); // c += m * v
@ -1151,7 +1151,7 @@ template<bool SYNCH>
void mpz_manager<SYNCH>::bitwise_not(unsigned sz, mpz const & a, mpz & c) {
SASSERT(is_nonneg(a));
if (is_small(a) && sz <= 63) {
int64 mask = (static_cast<int64>(1) << sz) - static_cast<int64>(1);
int64_t mask = (static_cast<int64_t>(1) << sz) - static_cast<int64_t>(1);
set_i64(c, (~ i64(a)) & mask);
}
else {
@ -1161,11 +1161,11 @@ void mpz_manager<SYNCH>::bitwise_not(unsigned sz, mpz const & a, mpz & c) {
set(c, 0);
while (sz > 0) {
mod(a1, m_two64, a2);
uint64 n = get_uint64(a2);
uint64 v = ~n;
uint64_t n = get_uint64(a2);
uint64_t v = ~n;
SASSERT(~v == n);
if (sz < 64) {
uint64 mask = (1ull << static_cast<uint64>(sz)) - 1ull;
uint64_t mask = (1ull << static_cast<uint64_t>(sz)) - 1ull;
v = mask & v;
}
TRACE("bitwise_not", tout << "sz: " << sz << ", v: " << v << ", n: " << n << "\n";);
@ -1265,7 +1265,7 @@ bool mpz_manager<SYNCH>::is_uint64(mpz const & a) const {
return false;
if (is_small(a))
return true;
if (sizeof(digit_t) == sizeof(uint64)) {
if (sizeof(digit_t) == sizeof(uint64_t)) {
return size(a) <= 1;
}
else {
@ -1286,9 +1286,9 @@ bool mpz_manager<SYNCH>::is_int64(mpz const & a) const {
#ifndef _MP_GMP
if (!is_abs_uint64(a))
return false;
uint64 num = big_abs_to_uint64(a);
uint64 msb = static_cast<uint64>(1) << 63;
uint64 msb_val = msb & num;
uint64_t num = big_abs_to_uint64(a);
uint64_t msb = static_cast<uint64_t>(1) << 63;
uint64_t msb_val = msb & num;
if (a.m_val >= 0) {
// non-negative number.
return (0 == msb_val);
@ -1307,54 +1307,54 @@ bool mpz_manager<SYNCH>::is_int64(mpz const & a) const {
}
template<bool SYNCH>
uint64 mpz_manager<SYNCH>::get_uint64(mpz const & a) const {
uint64_t mpz_manager<SYNCH>::get_uint64(mpz const & a) const {
if (is_small(a))
return static_cast<uint64>(a.m_val);
return static_cast<uint64_t>(a.m_val);
#ifndef _MP_GMP
SASSERT(a.m_ptr->m_size > 0);
return big_abs_to_uint64(a);
#else
// GMP version
if (sizeof(uint64) == sizeof(unsigned long)) {
if (sizeof(uint64_t) == sizeof(unsigned long)) {
return mpz_get_ui(*a.m_ptr);
}
else {
mpz_manager * _this = const_cast<mpz_manager*>(this);
mpz_set(_this->m_tmp, *a.m_ptr);
mpz_mod(_this->m_tmp, m_tmp, m_two32);
uint64 r = static_cast<uint64>(mpz_get_ui(m_tmp));
uint64_t r = static_cast<uint64_t>(mpz_get_ui(m_tmp));
mpz_set(_this->m_tmp, *a.m_ptr);
mpz_div(_this->m_tmp, m_tmp, m_two32);
r += static_cast<uint64>(mpz_get_ui(m_tmp)) << static_cast<uint64>(32);
r += static_cast<uint64_t>(mpz_get_ui(m_tmp)) << static_cast<uint64_t>(32);
return r;
}
#endif
}
template<bool SYNCH>
int64 mpz_manager<SYNCH>::get_int64(mpz const & a) const {
int64_t mpz_manager<SYNCH>::get_int64(mpz const & a) const {
if (is_small(a))
return static_cast<int64>(a.m_val);
return static_cast<int64_t>(a.m_val);
#ifndef _MP_GMP
SASSERT(is_int64(a));
uint64 num = big_abs_to_uint64(a);
uint64_t num = big_abs_to_uint64(a);
if (a.m_val < 0) {
if (num != 0 && (num << 1) == 0)
return INT64_MIN;
return -static_cast<int64>(num);
return -static_cast<int64_t>(num);
}
return static_cast<int64>(num);
return static_cast<int64_t>(num);
#else
// GMP
if (sizeof(int64) == sizeof(long) || mpz_fits_slong_p(*a.m_ptr)) {
if (sizeof(int64_t) == sizeof(long) || mpz_fits_slong_p(*a.m_ptr)) {
return mpz_get_si(*a.m_ptr);
}
else {
mpz_manager * _this = const_cast<mpz_manager*>(this);
mpz_mod(_this->m_tmp, *a.m_ptr, m_two32);
int64 r = static_cast<int64>(mpz_get_ui(m_tmp));
int64_t r = static_cast<int64_t>(mpz_get_ui(m_tmp));
mpz_div(_this->m_tmp, *a.m_ptr, m_two32);
r += static_cast<int64>(mpz_get_si(m_tmp)) << static_cast<int64>(32);
r += static_cast<int64_t>(mpz_get_si(m_tmp)) << static_cast<int64_t>(32);
return r;
}
#endif
@ -1370,7 +1370,7 @@ double mpz_manager<SYNCH>::get_double(mpz const & a) const {
unsigned sz = size(a);
for (unsigned i = 0; i < sz; i++) {
r += d * static_cast<double>(digits(a)[i]);
if (sizeof(digit_t) == sizeof(uint64))
if (sizeof(digit_t) == sizeof(uint64_t))
d *= static_cast<double>(UINT64_MAX); // 64-bit version
else
d *= static_cast<double>(UINT_MAX); // 32-bit version
@ -1696,7 +1696,7 @@ void mpz_manager<SYNCH>::mul2k(mpz & a, unsigned k) {
if (k == 0 || is_zero(a))
return;
if (is_small(a) && k < 32) {
set_i64(a, i64(a) * (static_cast<int64>(1) << k));
set_i64(a, i64(a) * (static_cast<int64_t>(1) << k));
return;
}
#ifndef _MP_GMP
@ -1798,9 +1798,9 @@ unsigned mpz_manager<SYNCH>::power_of_two_multiple(mpz const & a) {
if (sizeof(digit_t) == 8) {
// TODO: we can remove this if after we move to MPN
// In MPN the digit_t is always an unsigned integer
if (static_cast<uint64>(v) % (static_cast<uint64>(1) << 32) == 0) {
if (static_cast<uint64_t>(v) % (static_cast<uint64_t>(1) << 32) == 0) {
r += 32;
v = static_cast<digit_t>(static_cast<uint64>(v) / (static_cast<uint64>(1) << 32));
v = static_cast<digit_t>(static_cast<uint64_t>(v) / (static_cast<uint64_t>(1) << 32));
}
}
COUNT_DIGIT_RIGHT_ZEROS();

View file

@ -30,7 +30,7 @@ Revision History:
#include "util/mpn.h"
unsigned u_gcd(unsigned u, unsigned v);
uint64 u64_gcd(uint64 u, uint64 v);
uint64_t u64_gcd(uint64_t u, uint64_t v);
#ifdef _MP_GMP
typedef unsigned digit_t;
@ -192,11 +192,11 @@ class mpz_manager {
template<int IDX>
void set(mpz & a, int sign, unsigned sz);
static int64 i64(mpz const & a) { return static_cast<int64>(a.m_val); }
static int64_t i64(mpz const & a) { return static_cast<int64_t>(a.m_val); }
void set_big_i64(mpz & c, int64 v);
void set_big_i64(mpz & c, int64_t v);
void set_i64(mpz & c, int64 v) {
void set_i64(mpz & c, int64_t v) {
if (v >= INT_MIN && v <= INT_MAX) {
del(c);
c.m_val = static_cast<int>(v);
@ -208,7 +208,7 @@ class mpz_manager {
}
}
void set_big_ui64(mpz & c, uint64 v);
void set_big_ui64(mpz & c, uint64_t v);
#ifndef _MP_GMP
static unsigned capacity(mpz const & c) { return c.m_ptr->m_capacity; }
@ -221,24 +221,24 @@ class mpz_manager {
static bool is_abs_uint64(mpz const & a) {
if (is_small(a))
return true;
if (sizeof(digit_t) == sizeof(uint64))
if (sizeof(digit_t) == sizeof(uint64_t))
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) {
static uint64_t 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))
if (sizeof(digit_t) == sizeof(uint64_t))
// 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])));
return ((static_cast<uint64_t>(digits(a)[1]) << 32) | (static_cast<uint64_t>(digits(a)[0])));
}
template<int IDX>
@ -426,8 +426,8 @@ public:
void machine_div_rem(mpz const & a, mpz const & b, mpz & q, mpz & r) {
STRACE("mpz", tout << "[mpz-ext] divrem(" << to_string(a) << ", " << to_string(b) << ") == ";);
if (is_small(a) && is_small(b)) {
int64 _a = i64(a);
int64 _b = i64(b);
int64_t _a = i64(a);
int64_t _b = i64(b);
set_i64(q, _a / _b);
set_i64(r, _a % _b);
}
@ -686,16 +686,16 @@ public:
if (val <= INT_MAX)
set(a, static_cast<int>(val));
else
set(a, static_cast<int64>(static_cast<uint64>(val)));
set(a, static_cast<int64_t>(static_cast<uint64_t>(val)));
}
void set(mpz & a, char const * val);
void set(mpz & a, int64 val) {
void set(mpz & a, int64_t val) {
set_i64(a, val);
}
void set(mpz & a, uint64 val) {
void set(mpz & a, uint64_t val) {
if (val < INT_MAX) {
del(a);
a.m_val = static_cast<int>(val);
@ -729,9 +729,9 @@ public:
bool is_int64(mpz const & a) const;
uint64 get_uint64(mpz const & a) const;
uint64_t get_uint64(mpz const & a) const;
int64 get_int64(mpz const & a) const;
int64_t get_int64(mpz const & a) const;
bool is_uint(mpz const & a) const { return is_uint64(a) && get_uint64(a) < UINT_MAX; }

View file

@ -87,7 +87,7 @@ public:
setup_p();
}
mpzzp_manager(numeral_manager & _m, uint64 p, bool prime = true):
mpzzp_manager(numeral_manager & _m, uint64_t p, bool prime = true):
m_manager(_m),
m_z(false) {
m().set(m_p, p);
@ -120,7 +120,7 @@ public:
void set_z() { m_z = true; }
void set_zp(mpz const & new_p) { m_z = false; m_p_prime = true; m().set(m_p, new_p); setup_p(); }
void set_zp(uint64 new_p) { m_z = false; m_p_prime = true; m().set(m_p, new_p); setup_p(); }
void set_zp(uint64_t new_p) { m_z = false; m_p_prime = true; m().set(m_p, new_p); setup_p(); }
// p = p^2
void set_p_sq() { SASSERT(!m_z); m_p_prime = false; m().mul(m_p, m_p, m_p); setup_p(); }
void set_zp_swap(mpz & new_p) { SASSERT(!m_z); m().swap(m_p, new_p); setup_p(); }
@ -230,14 +230,14 @@ public:
void set(mpz & a, int val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, unsigned val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, char const * val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, int64 val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, uint64 val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, int64_t val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, uint64_t val) { m().set(a, val); p_normalize(a); }
void set(mpz & a, mpz const & val) { m().set(a, val); p_normalize(a); }
bool is_uint64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().is_uint64(a); }
bool is_int64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().is_int64(a); }
uint64 get_uint64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().get_uint64(a); }
int64 get_int64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().get_int64(a); }
uint64_t get_uint64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().get_uint64(a); }
int64_t get_int64(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().get_int64(a); }
double get_double(mpz & a) const { const_cast<mpzzp_manager*>(this)->p_normalize(a); return m().get_double(a); }
void power(mpz const & a, unsigned k, mpz & b) {
SASSERT(is_p_normalized(a));
@ -265,8 +265,8 @@ public:
bool is_uint64(mpz const & a) const { return m().is_uint64(a); }
bool is_int64(mpz const & a) const { return m().is_int64(a); }
uint64 get_uint64(mpz const & a) const { return m().get_uint64(a); }
int64 get_int64(mpz const & a) const { return m().get_int64(a); }
uint64_t get_uint64(mpz const & a) const { return m().get_uint64(a); }
int64_t get_int64(mpz const & a) const { return m().get_int64(a); }
void mul2k(mpz & a, unsigned k) { m().mul2k(a, k); p_normalize(a); }
void mul2k(mpz const & a, unsigned k, mpz & r) { m().mul2k(a, k, r); p_normalize(r); }

View file

@ -26,11 +26,11 @@ prime_generator::prime_generator() {
process_next_k_numbers(128);
}
void prime_generator::process_next_k_numbers(uint64 k) {
svector<uint64> todo;
uint64 begin = m_primes.back() + 2;
uint64 end = begin + k;
for (uint64 i = begin; i < end; i+=2) {
void prime_generator::process_next_k_numbers(uint64_t k) {
svector<uint64_t> todo;
uint64_t begin = m_primes.back() + 2;
uint64_t end = begin + k;
for (uint64_t i = begin; i < end; i+=2) {
todo.push_back(i);
}
unsigned j = 1;
@ -38,7 +38,7 @@ void prime_generator::process_next_k_numbers(uint64 k) {
while (!todo.empty()) {
unsigned sz = m_primes.size();
for (; j < sz; j++) {
uint64 p = m_primes[j];
uint64_t p = m_primes[j];
unsigned todo_sz = todo.size();
unsigned k1 = 0;
unsigned k2 = 0;
@ -59,7 +59,7 @@ void prime_generator::process_next_k_numbers(uint64 k) {
return;
}
}
uint64 p = m_primes.back();
uint64_t p = m_primes.back();
p = p*p;
unsigned todo_sz = todo.size();
unsigned k1 = 0;
@ -83,7 +83,7 @@ void prime_generator::finalize() {
m_primes.finalize();
}
uint64 prime_generator::operator()(unsigned idx) {
uint64_t prime_generator::operator()(unsigned idx) {
if (idx < m_primes.size())
return m_primes[idx];
if (idx > PRIME_LIST_MAX_SIZE)
@ -109,14 +109,14 @@ prime_iterator::prime_iterator(prime_generator * g):m_idx(0) {
}
}
uint64 prime_iterator::next() {
uint64_t prime_iterator::next() {
unsigned idx = m_idx;
m_idx++;
if (!m_global) {
return (*m_generator)(idx);
}
else {
uint64 r;
uint64_t r;
#pragma omp critical (prime_iterator)
{
r = (*m_generator)(idx);

View file

@ -32,11 +32,11 @@ public:
\brief Prime generator
*/
class prime_generator {
svector<uint64> m_primes;
void process_next_k_numbers(uint64 k);
svector<uint64_t> m_primes;
void process_next_k_numbers(uint64_t k);
public:
prime_generator();
uint64 operator()(unsigned idx);
uint64_t operator()(unsigned idx);
void finalize();
};
@ -46,7 +46,7 @@ class prime_iterator {
bool m_global;
public:
prime_iterator(prime_generator * g = nullptr);
uint64 next();
uint64_t next();
static void finalize();
/*
ADD_FINALIZER('prime_iterator::finalize();')

View file

@ -59,10 +59,10 @@ public:
explicit rational(char const * v) { m().set(m_val, v); }
struct i64 {};
rational(int64 i, i64) { m().set(m_val, i); }
rational(int64_t i, i64) { m().set(m_val, i); }
struct ui64 {};
rational(uint64 i, ui64) { m().set(m_val, i); }
rational(uint64_t i, ui64) { m().set(m_val, i); }
~rational() { m().del(m_val); }
@ -98,9 +98,9 @@ public:
bool is_int64() const { return m().is_int64(m_val); }
uint64 get_uint64() const { return m().get_uint64(m_val); }
uint64_t get_uint64() const { return m().get_uint64(m_val); }
int64 get_int64() const { return m().get_int64(m_val); }
int64_t get_int64() const { return m().get_int64(m_val); }
bool is_unsigned() const { return is_uint64() && (get_uint64() < (1ull << 32)); }
@ -113,7 +113,7 @@ public:
if (is_small() && is_int()) return true;
// we don't assume that if it is small, then it is int32.
if (!is_int64()) return false;
int64 v = get_int64();
int64_t v = get_int64();
return INT_MIN <= v && v <= INT_MAX;
}

View file

@ -26,7 +26,7 @@ reslimit::reslimit():
m_limit(0) {
}
uint64 reslimit::count() const {
uint64_t reslimit::count() const {
return m_count;
}
@ -41,7 +41,7 @@ bool reslimit::inc(unsigned offset) {
}
void reslimit::push(unsigned delta_limit) {
uint64 new_limit = delta_limit + m_count;
uint64_t new_limit = delta_limit + m_count;
if (new_limit <= m_count) {
new_limit = 0;
}

View file

@ -24,9 +24,9 @@ Revision History:
class reslimit {
volatile unsigned m_cancel;
bool m_suspend;
uint64 m_count;
uint64 m_limit;
svector<uint64> m_limits;
uint64_t m_count;
uint64_t m_limit;
svector<uint64_t> m_limits;
ptr_vector<reslimit> m_children;
void set_cancel(unsigned f);
@ -41,7 +41,7 @@ public:
bool inc();
bool inc(unsigned offset);
uint64 count() const;
uint64_t count() const;
bool get_cancel_flag() const { return m_cancel > 0 && !m_suspend; }

View file

@ -46,9 +46,9 @@ public:
s_integer(const s_integer & r):m_val(r.m_val) {}
explicit s_integer(int n):m_val(n) {}
struct i64 {};
explicit s_integer(int64 i, i64):m_val(static_cast<int>(i)) {}
explicit s_integer(int64_t i, i64):m_val(static_cast<int>(i)) {}
struct ui64 {};
explicit s_integer(uint64 i, ui64):m_val(static_cast<int>(i)) {}
explicit s_integer(uint64_t i, ui64):m_val(static_cast<int>(i)) {}
explicit s_integer(const char * str);
explicit s_integer(const rational & r):m_val(static_cast<int>(r.get_int64())) {}
@ -60,8 +60,8 @@ public:
static bool is_int64() { return true; }
static bool is_uint64() { return true; }
int get_int() const { return m_val; }
int64 get_int64() const { return m_val; }
uint64 get_uint64() const { return m_val; }
int64_t get_int64() const { return m_val; }
uint64_t get_uint64() const { return m_val; }
static bool is_unsigned() { return true; }
unsigned get_unsigned() const { return static_cast<unsigned>(m_val); }
s_integer const& get_s_integer() const { return *this; }

View file

@ -35,7 +35,7 @@ class total_order {
struct cell {
cell * m_next;
cell * m_prev;
uint64 m_val;
uint64_t m_val;
T m_data;
};
@ -53,11 +53,11 @@ class total_order {
m_base.m_val = 0;
}
uint64 v(cell * a) const { return a->m_val; }
uint64_t v(cell * a) const { return a->m_val; }
uint64 vb(cell * a) const { return v(a) - v(base()); }
uint64_t vb(cell * a) const { return v(a) - v(base()); }
uint64 vbn(cell * a) const { return a->m_next == base() ? UINT64_MAX : vb(a->m_next); }
uint64_t vbn(cell * a) const { return a->m_next == base() ? UINT64_MAX : vb(a->m_next); }
cell * mk_cell(T const & a) {
SASSERT(!m_map.contains(a));
@ -84,18 +84,18 @@ class total_order {
}
void _insert_after(cell * a, cell * b) {
uint64 vb_a = vb(a);
uint64 vbn_a = vbn(a);
uint64_t vb_a = vb(a);
uint64_t vbn_a = vbn(a);
SASSERT(vb_a < vbn_a);
if (vbn_a < 2 || (vb_a > vbn_a - 2)) {
TRACE("total_order", tout << "relabeling...\n"; tout << "\n";);
uint64 v0 = v(a);
unsigned sz = size();
uint64 ideal_gap = UINT64_MAX / sz;
uint64 goal_gap = ideal_gap / 32;
cell * c = a->m_next->m_next;
unsigned j = 2;
uint64 curr_gap = (v(c) - v0) / j;
uint64_t v0 = v(a);
unsigned sz = size();
uint64_t ideal_gap = UINT64_MAX / sz;
uint64_t goal_gap = ideal_gap / 32;
cell * c = a->m_next->m_next;
unsigned j = 2;
uint64_t curr_gap = (v(c) - v0) / j;
while (j < sz && curr_gap < goal_gap) {
j++;
c = c->m_next;
@ -105,7 +105,7 @@ class total_order {
if (j == sz)
curr_gap = ideal_gap;
c = a->m_next;
uint64 inc = curr_gap;
uint64_t inc = curr_gap;
for (unsigned i = 0; i < j; i++) {
c->m_val = v0 + inc;
c = c->m_next;
@ -116,7 +116,7 @@ class total_order {
vbn_a = vbn(a);
}
SASSERT(vb_a <= vbn_a - 2);
uint64 vb_b = vb_a + ((vbn_a - vb_a)/2);
uint64_t vb_b = vb_a + ((vbn_a - vb_a)/2);
SASSERT(vb_b > vb_a);
SASSERT(vb_b < vbn_a);
b->m_val = vb_b + v(base());

View file

@ -80,7 +80,7 @@ unsigned log2(unsigned v) {
return r;
}
unsigned uint64_log2(uint64 v) {
unsigned uint64_log2(uint64_t v) {
unsigned r = 0;
if (v & 0xFFFFFFFF00000000ull) {
v >>= 32;

View file

@ -29,23 +29,11 @@ Revision History:
#define SIZE_MAX std::numeric_limits<std::size_t>::max()
#endif
#ifndef uint64
typedef unsigned long long uint64;
#endif
static_assert(sizeof(uint64) == 8, "64 bits please");
#ifndef int64
typedef long long int64;
#endif
static_assert(sizeof(int64) == 8, "64 bits");
#ifndef INT64_MIN
#define INT64_MIN static_cast<int64>(0x8000000000000000ull)
#define INT64_MIN static_cast<int64_t>(0x8000000000000000ull)
#endif
#ifndef INT64_MAX
#define INT64_MAX static_cast<int64>(0x7fffffffffffffffull)
#define INT64_MAX static_cast<int64_t>(0x7fffffffffffffffull)
#endif
#ifndef UINT64_MAX
#define UINT64_MAX 0xffffffffffffffffull
@ -110,7 +98,7 @@ inline unsigned next_power_of_two(unsigned v) {
\brief Return the position of the most significant bit.
*/
unsigned log2(unsigned v);
unsigned uint64_log2(uint64 v);
unsigned uint64_log2(uint64_t v);
static_assert(sizeof(unsigned) == 4, "unsigned are 32 bits");
@ -136,11 +124,11 @@ static inline unsigned get_num_1bits(unsigned v) {
// Remark: on gcc, the operators << and >> do not produce zero when the second argument >= 64.
// So, I'm using the following two definitions to fix the problem
static inline uint64 shift_right(uint64 x, uint64 y) {
static inline uint64_t shift_right(uint64_t x, uint64_t y) {
return y < 64ull ? (x >> y) : 0ull;
}
static inline uint64 shift_left(uint64 x, uint64 y) {
static inline uint64_t shift_left(uint64_t x, uint64_t y) {
return y < 64ull ? (x << y) : 0ull;
}