|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83060 - in trunk: boost/multiprecision/cpp_int libs/multiprecision/doc libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-02-21 08:05:43
Author: johnmaddock
Date: 2013-02-21 08:05:41 EST (Thu, 21 Feb 2013)
New Revision: 83060
URL: http://svn.boost.org/trac/boost/changeset/83060
Log:
Fix sign of division in cpp_int when the values are small enough to fit in a double_limb_type.
Add test cases for above.
Fixes #8126.
Text files modified:
trunk/boost/multiprecision/cpp_int/divide.hpp | 6 ++++++
trunk/libs/multiprecision/doc/multiprecision.qbk | 2 ++
trunk/libs/multiprecision/test/test_cpp_int.cpp | 19 +++++++++++++++++++
3 files changed, 27 insertions(+), 0 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-21 08:05:41 EST (Thu, 21 Feb 2013)
@@ -114,7 +114,10 @@
if(r_order == 0)
{
if(result)
+ {
*result = px[0] / py[0];
+ result->sign(x.sign() != y.sign());
+ }
r = px[0] % py[0];
return;
}
@@ -126,7 +129,10 @@
(static_cast<double_limb_type>(py[1]) << CppInt1::limb_bits) | py[0]
: py[0];
if(result)
+ {
*result = a / b;
+ result->sign(x.sign() != y.sign());
+ }
r = a % b;
return;
}
Modified: trunk/libs/multiprecision/doc/multiprecision.qbk
==============================================================================
--- trunk/libs/multiprecision/doc/multiprecision.qbk (original)
+++ trunk/libs/multiprecision/doc/multiprecision.qbk 2013-02-21 08:05:41 EST (Thu, 21 Feb 2013)
@@ -3617,6 +3617,8 @@
* [*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
+to fit in a `double_limb_type`. See [@https://svn.boost.org/trac/boost/ticket/8126 8126].
[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-21 08:05:41 EST (Thu, 21 Feb 2013)
@@ -470,6 +470,25 @@
}
}
+ //
+ // Specific bug report tests come last:
+ //
+ // Bug https://svn.boost.org/trac/boost/ticket/8126:
+ test_type a("-4294967296");
+ test_type b("4294967296");
+ test_type c("-1");
+ a = (a / b);
+ BOOST_CHECK_EQUAL(a, -1);
+ a = -4294967296;
+ a = (a / b) * c;
+ BOOST_CHECK_EQUAL(a, 1);
+ a = -23;
+ b = 23;
+ a = (a / b) * c;
+ BOOST_CHECK_EQUAL(a, 1);
+ a = -23;
+ a = (a / b) / c;
+ BOOST_CHECK_EQUAL(a, 1);
}
};
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