[GIT] ppl/ppl(master): For code clarity purposes, better distinguish signed /unsigned operations.

Module: ppl/ppl Branch: master Commit: 5ac71293891dbc160c066a80738a4bd27b93a450 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=5ac71293891db...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Sat Feb 25 16:12:58 2012 +0100
For code clarity purposes, better distinguish signed/unsigned operations. Detected by ECLAIR service utypflag.
---
src/Bit_Row.cc | 6 ++++-- src/CO_Tree.cc | 9 +++++---- src/checked_float.inlines.hh | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/Bit_Row.cc b/src/Bit_Row.cc index c303fae..d250197 100644 --- a/src/Bit_Row.cc +++ b/src/Bit_Row.cc @@ -55,7 +55,8 @@ PPL::Bit_Row::next(unsigned long position) const { // return (r == C_Integer<unsigned long>::max) ? -1 : r; // </CODE>
- mp_size_t li = static_cast<mp_size_t>(position / PPL_BITS_PER_GMP_LIMB); + const unsigned long uli = position / PPL_BITS_PER_GMP_LIMB; + mp_size_t li = static_cast<mp_size_t>(uli); const mp_size_t vec_size = vec->_mp_size; PPL_ASSERT(vec_size >= 0); if (li >= vec_size) @@ -104,7 +105,8 @@ PPL::Bit_Row::prev(unsigned long position) const {
const mp_size_t vec_size = vec->_mp_size; PPL_ASSERT(vec_size > 0); - mp_size_t li = static_cast<mp_size_t>(position / PPL_BITS_PER_GMP_LIMB); + const unsigned long uli = position / PPL_BITS_PER_GMP_LIMB; + mp_size_t li = static_cast<mp_size_t>(uli);
mp_limb_t limb; mp_srcptr p = vec->_mp_d; diff --git a/src/CO_Tree.cc b/src/CO_Tree.cc index 4a70f04..0b388a1 100644 --- a/src/CO_Tree.cc +++ b/src/CO_Tree.cc @@ -893,8 +893,9 @@ PPL::CO_Tree --subtree_size; }
- PPL_ASSERT(first_unused_index >= indexes); - return static_cast<dimension_type>(first_unused_index - indexes); + ptrdiff_t distance = first_unused_index - indexes; + PPL_ASSERT(distance >= 0); + return static_cast<dimension_type>(distance); }
void @@ -907,8 +908,8 @@ PPL::CO_Tree::redistribute_elements_in_subtree( bool add_element) {
// This is static and with static allocation, to improve performance. - // sizeof_to_bits(sizeof(dimension_type)) is the maximum k such that 2^k-1 is a - // dimension_type, so it is the maximum tree height. + // sizeof_to_bits(sizeof(dimension_type)) is the maximum k such that + // 2^k-1 is a dimension_type, so it is the maximum tree height. // For each node level, the stack may contain up to two element (one for the // subtree rooted at the right son of a node of that level, and one for the // node itself). An additional element can be at the top of the tree. diff --git a/src/checked_float.inlines.hh b/src/checked_float.inlines.hh index 79166c0..08b7251 100644 --- a/src/checked_float.inlines.hh +++ b/src/checked_float.inlines.hh @@ -885,14 +885,17 @@ assign_float_mpq(T& to, const mpq_class& from, Rounding_Dir dir) { - exponent); mpz_t mantissa; mpz_init(mantissa); - long shift = static_cast<long>(needed_bits) - exponent; - if (shift > 0) { - mpz_mul_2exp(mantissa, numer_z, static_cast<unsigned long>(shift)); - numer_z = mantissa; - } - else if (shift < 0) { - mpz_mul_2exp(mantissa, denom_z, static_cast<unsigned long>(-shift)); - denom_z = mantissa; + { + long shift = static_cast<long>(needed_bits) - exponent; + if (shift > 0) { + mpz_mul_2exp(mantissa, numer_z, static_cast<unsigned long>(shift)); + numer_z = mantissa; + } + else if (shift < 0) { + shift = -shift; + mpz_mul_2exp(mantissa, denom_z, static_cast<unsigned long>(shift)); + denom_z = mantissa; + } } mpz_t r; mpz_init(r);
participants (1)
-
Enea Zaffanella