Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84925 - in trunk: boost/multiprecision/cpp_int libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-07-01 13:06:13


Author: johnmaddock
Date: 2013-07-01 13:06:12 EDT (Mon, 01 Jul 2013)
New Revision: 84925
URL: http://svn.boost.org/trac/boost/changeset/84925

Log:
Fix left shift operator.
Fixes #8741.

Text files modified:
   trunk/boost/multiprecision/cpp_int/bitwise.hpp | 12 ++----------
   trunk/libs/multiprecision/test/test_cpp_int.cpp | 6 ++++++
   2 files changed, 8 insertions(+), 10 deletions(-)

Modified: trunk/boost/multiprecision/cpp_int/bitwise.hpp
==============================================================================
--- trunk/boost/multiprecision/cpp_int/bitwise.hpp Mon Jul 1 13:05:47 2013 (r84924)
+++ trunk/boost/multiprecision/cpp_int/bitwise.hpp 2013-07-01 13:06:12 EDT (Mon, 01 Jul 2013) (r84925)
@@ -229,12 +229,6 @@
    limb_type offset = static_cast<limb_type>(s / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
    limb_type shift = static_cast<limb_type>(s % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
 
- /*
- static const unsigned max_bits = max_bits<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value;
- static const unsigned max_limbs = max_bits / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits
- + (max_bits % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits ? 1 : 0);
- */
-
    unsigned ors = result.size();
    if((ors == 1) && (!*result.limbs()))
       return; // shifting zero yields zero.
@@ -244,8 +238,7 @@
    rs += offset;
    result.resize(rs, rs);
    bool truncated = result.size() != rs;
- if(truncated)
- rs = result.size();
+
    typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer pr = result.limbs();
 
    if(offset > rs)
@@ -255,11 +248,10 @@
       return;
    }
 
- unsigned i = 0;
+ unsigned i = rs - result.size();
    if(shift)
    {
       // This code only works when shift is non-zero, otherwise we invoke undefined behaviour!
- i = 0;
       if(!truncated)
       {
          if(rs > ors + offset)

Modified: trunk/libs/multiprecision/test/test_cpp_int.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_int.cpp Mon Jul 1 13:05:47 2013 (r84924)
+++ trunk/libs/multiprecision/test/test_cpp_int.cpp 2013-07-01 13:06:12 EDT (Mon, 01 Jul 2013) (r84925)
@@ -173,6 +173,12 @@
          {
             BOOST_CHECK_EQUAL(mpz_int(a << i).str(), test_type(a1 << i).str());
          }
+ else if(!is_checked_cpp_int<test_type>::value)
+ {
+ test_type t1(mpz_int(a << i).str());
+ test_type t2 = a1 << i;
+ BOOST_CHECK_EQUAL(t1, t2);
+ }
          BOOST_CHECK_EQUAL(mpz_int(a >> i).str(), test_type(a1 >> i).str());
       }
       // gcd/lcm


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk