Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86303 - sandbox/multiprecision.cpp_bin_float/boost/multiprecision
From: john_at_[hidden]
Date: 2013-10-14 13:38:05


Author: johnmaddock
Date: 2013-10-14 13:38:04 EDT (Mon, 14 Oct 2013)
New Revision: 86303
URL: http://svn.boost.org/trac/boost/changeset/86303

Log:
Fix some more errors which occur when bit count is smaller than the limb-size.

Text files modified:
   sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp | 30 ++++++++++++++++++++----------
   1 files changed, 20 insertions(+), 10 deletions(-)

Modified: sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp
==============================================================================
--- sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp Mon Oct 14 12:44:36 2013 (r86302)
+++ sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp 2013-10-14 13:38:04 EDT (Mon, 14 Oct 2013) (r86303)
@@ -217,8 +217,16 @@
          typedef typename boost::multiprecision::detail::canonical<ui_type, rep_type>::type ar_type;
          m_data = static_cast<ar_type>(fi);
          unsigned shift = msb(fi);
- m_exponent = shift;
- eval_left_shift(m_data, bit_count - shift - 1);
+ if(shift >= bit_count)
+ {
+ m_exponent = shift;
+ m_data = fi >> shift + 1 - bit_count;
+ }
+ else
+ {
+ m_exponent = shift;
+ eval_left_shift(m_data, bit_count - shift - 1);
+ }
          BOOST_ASSERT(eval_bit_test(m_data, bit_count-1));
          m_sign = i < 0;
       }
@@ -784,14 +792,15 @@
       // how we'll be rounding.
       //
       BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator>::bit_count - 1));
- eval_left_shift(q, limb_bits);
- res.exponent() -= limb_bits;
+ static const unsigned lshift = cpp_bin_float<Digits, DigitBase, Allocator>::bit_count < limb_bits ? 2 : limb_bits;
+ eval_left_shift(q, lshift);
+ res.exponent() -= lshift;
       eval_left_shift(r, 1u);
       int c = r.compare(v.bits());
       if(c == 0)
- q.limbs()[0] |= static_cast<limb_type>(1u) << (limb_bits - 1);
+ q.limbs()[0] |= static_cast<limb_type>(1u) << (lshift - 1);
       else if(c > 0)
- q.limbs()[0] |= (static_cast<limb_type>(1u) << (limb_bits - 1)) + static_cast<limb_type>(1u);
+ q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u);
    }
    copy_and_round(res, q);
 }
@@ -890,14 +899,15 @@
       // how we'll be rounding.
       //
       BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator>::bit_count - 1));
- eval_left_shift(q, limb_bits);
- res.exponent() -= limb_bits;
+ static const unsigned lshift = cpp_bin_float<Digits, DigitBase, Allocator>::bit_count < limb_bits ? 2 : limb_bits;
+ eval_left_shift(q, lshift);
+ res.exponent() -= lshift;
       eval_left_shift(r, 1u);
       int c = r.compare(number<typename cpp_bin_float<Digits, DigitBase, Allocator>::double_rep_type>::canonical_value(v));
       if(c == 0)
- q.limbs()[0] |= static_cast<limb_type>(1u) << (limb_bits - 1);
+ q.limbs()[0] |= static_cast<limb_type>(1u) << (lshift - 1);
       else if(c > 0)
- q.limbs()[0] |= (static_cast<limb_type>(1u) << (limb_bits - 1)) + static_cast<limb_type>(1u);
+ q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u);
    }
    copy_and_round(res, q);
 }


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