$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r50542 - in sandbox/mp_math: boost/mp_math/mp_int/detail libs/mp_math/test
From: baraclese_at_[hidden]
Date: 2009-01-11 08:56:26
Author: baraclese
Date: 2009-01-11 08:56:25 EST (Sun, 11 Jan 2009)
New Revision: 50542
URL: http://svn.boost.org/trac/boost/changeset/50542
Log:
* mp_int/detail/integral_ops.hpp
  Fixed a few more bugs reported by Nathan Kitchen.
Text files modified: 
   sandbox/mp_math/boost/mp_math/mp_int/detail/integral_ops.hpp |    20 ++++++++++++--------                    
   sandbox/mp_math/libs/mp_math/test/cmp.cpp                    |    29 +++++++++++++++++++++--------           
   2 files changed, 33 insertions(+), 16 deletions(-)
Modified: sandbox/mp_math/boost/mp_math/mp_int/detail/integral_ops.hpp
==============================================================================
--- sandbox/mp_math/boost/mp_math/mp_int/detail/integral_ops.hpp	(original)
+++ sandbox/mp_math/boost/mp_math/mp_int/detail/integral_ops.hpp	2009-01-11 08:56:25 EST (Sun, 11 Jan 2009)
@@ -132,18 +132,18 @@
     static const int dd = MpInt::valid_bits;
     static const int m = dd < ud ? dd : ud;
     static const int h = m / 2;
-    /* set h bits at a time */
+    // set h bits at a time
     for (int i = 0; i < ud / h; ++i)
     {
-      /* shift the number up h bits */
+      // shift the number up h bits
       lhs <<= h;
       // TODO optimize shift. only need to call grow_capacity once here
       // then use lower level shift_left(lhs.digits_, h);
 
-      /* OR in the top h bits of the source */
+      // OR in the top h bits of the source
       lhs[0] |= (rhs >> (ud-h)) & (power<IntegralT,2,h>::value - 1);
 
-      /* shift the source up to the next h bits */
+      // shift the source up to the next h bits
       rhs <<= h;
     }
     lhs.clamp();
@@ -190,9 +190,9 @@
 bool
 integral_ops_impl<IntegralT, MpInt, true>::equal(const MpInt& lhs, IntegralT rhs)
 {
-  const int r_sign = rhs < 0 ? -1 : 1;
+  const int rhs_sign = rhs < 0 ? -1 : 1;
 
-  if (lhs.sign() != r_sign)
+  if (lhs.sign() != rhs_sign)
     return false;
 
   if (lhs.size() > q)
@@ -224,8 +224,12 @@
   if (lhs.sign() == 1 && rhs < 0)
     return false;
 
-  if (lhs.size() > q)
-    return false;
+  static const typename MpInt::size_type rhs_precision =
+    static_cast<typename MpInt::size_type>(
+        std::numeric_limits<IntegralT>::digits);
+
+  if (lhs.precision() > rhs_precision)
+    return lhs.sign() == -1;
 
   return lhs.template to_integral<IntegralT>() < rhs;
 }
Modified: sandbox/mp_math/libs/mp_math/test/cmp.cpp
==============================================================================
--- sandbox/mp_math/libs/mp_math/test/cmp.cpp	(original)
+++ sandbox/mp_math/libs/mp_math/test/cmp.cpp	2009-01-11 08:56:25 EST (Sun, 11 Jan 2009)
@@ -1,4 +1,4 @@
-// Copyright Kevin Sopp 2008.
+// Copyright Kevin Sopp 2008 - 2009.
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
@@ -106,12 +106,31 @@
   BOOST_CHECK_EQUAL(x, -32101);
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_integral_type, mp_int_type, mp_int_types)
+BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_integral_type1, mp_int_type, mp_int_types)
 {
   const mp_int_type x("123456789");
   BOOST_CHECK_LT(x, 123456790);
 }
 
+BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_integral_type2, mp_int_type, mp_int_types)
+{
+  const mp_int_type x("0x100000000");
+  BOOST_CHECK_LE(1, x);
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_integral_type3, mp_int_type, mp_int_types)
+{
+  const mp_int_type x("-0x100000000");
+  BOOST_CHECK_LT(x, -1);
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_integral_type4, mp_int_type, mp_int_types)
+{
+  mp_int_type x(std::numeric_limits<int>::min());
+  x -= 1;
+  BOOST_CHECK_LT(x, std::numeric_limits<int>::min());
+}
+
 BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_lt_unsigned_integral_type, mp_int_type, mp_int_types)
 {
   const mp_int_type x("123456789");
@@ -130,12 +149,6 @@
   BOOST_CHECK_LE(x, 32102);
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_le_integral_type3, mp_int_type, mp_int_types)
-{
-  const mp_int_type x("0x100000000");
-  BOOST_CHECK_LE(1, x);
-}
-
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(cmp_mp_int_le_unsigned_integral_type, mp_int_type, mp_int_types)
 {