Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83128 - in trunk: boost/multiprecision/cpp_int libs/multiprecision/doc libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-02-24 08:20:47


Author: johnmaddock
Date: 2013-02-24 08:20:46 EST (Sun, 24 Feb 2013)
New Revision: 83128
URL: http://svn.boost.org/trac/boost/changeset/83128

Log:
Fix bug in division of zero.
Document and add tests.
Fixes #8160.
Text files modified:
   trunk/boost/multiprecision/cpp_int/divide.hpp | 2 ++
   trunk/libs/multiprecision/doc/multiprecision.qbk | 5 ++++-
   trunk/libs/multiprecision/test/test_cpp_int.cpp | 7 +++++++
   3 files changed, 13 insertions(+), 1 deletions(-)

Modified: trunk/boost/multiprecision/cpp_int/divide.hpp
==============================================================================
--- trunk/boost/multiprecision/cpp_int/divide.hpp (original)
+++ trunk/boost/multiprecision/cpp_int/divide.hpp 2013-02-24 08:20:46 EST (Sun, 24 Feb 2013)
@@ -339,6 +339,8 @@
    if((r_order == 0) && (*pr == 0))
    {
       // All the limbs in x are zero, so is the result:
+ if(result)
+ *result = static_cast<limb_type>(0u);
       return;
    }
    //

Modified: trunk/libs/multiprecision/doc/multiprecision.qbk
==============================================================================
--- trunk/libs/multiprecision/doc/multiprecision.qbk (original)
+++ trunk/libs/multiprecision/doc/multiprecision.qbk 2013-02-24 08:20:46 EST (Sun, 24 Feb 2013)
@@ -3617,8 +3617,11 @@
 * [*Breaking change] renamed `rational_adapter` to `rational_adaptor`.
 * Add support for [mpfi].
 * Add logged_adaptor.
-* Fix bug in integer division that results in incorrect sign of `cpp_int` when both arguments are small enough
+* Fixed bug in integer division of `cpp_int` that results in incorrect sign of `cpp_int` when both arguments are small enough
 to fit in a `double_limb_type`. See [@https://svn.boost.org/trac/boost/ticket/8126 8126].
+* Fixed bug in subtraction of a single limb in `cpp_int` that results in incorrect value when the result should have a 0
+in the last limb: [@https://svn.boost.org/trac/boost/ticket/8133 8133].
+* Fixed bug in `cpp_int` where division of 0 by something doesn't get zero in the result: [@https://svn.boost.org/trac/boost/ticket/8160 8160].
 
 [h4 1.53]
 

Modified: trunk/libs/multiprecision/test/test_cpp_int.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_int.cpp (original)
+++ trunk/libs/multiprecision/test/test_cpp_int.cpp 2013-02-24 08:20:46 EST (Sun, 24 Feb 2013)
@@ -458,6 +458,13 @@
       a = -test_type("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
       a /= (1 + test_type("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
       BOOST_CHECK_EQUAL(a, 0);
+ // https://svn.boost.org/trac/boost/ticket/8160
+ a = 1;
+ a = 0 / test_type(1);
+ BOOST_CHECK_EQUAL(a, 0);
+ a = 1;
+ a = 0 % test_type(25);
+ BOOST_CHECK_EQUAL(a, 0);
    }
 
    void test()


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