Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81638 - trunk/boost/multiprecision
From: e_float_at_[hidden]
Date: 2012-11-30 15:22:11


Author: christopher_kormanyos
Date: 2012-11-30 15:22:10 EST (Fri, 30 Nov 2012)
New Revision: 81638
URL: http://svn.boost.org/trac/boost/changeset/81638

Log:
Improved cpp_dec_float::extract_parts to handle sizeof(double) exceeding 8 bytes.
Text files modified:
   trunk/boost/multiprecision/cpp_dec_float.hpp | 21 ++++++++++++++++++---
   1 files changed, 18 insertions(+), 3 deletions(-)

Modified: trunk/boost/multiprecision/cpp_dec_float.hpp
==============================================================================
--- trunk/boost/multiprecision/cpp_dec_float.hpp (original)
+++ trunk/boost/multiprecision/cpp_dec_float.hpp 2012-11-30 15:22:10 EST (Fri, 30 Nov 2012)
@@ -1484,9 +1484,24 @@
       ++exponent;
    }
 
- mantissa = static_cast<double>(data[0])
- + (static_cast<double>(data[1]) / static_cast<double>(cpp_dec_float_elem_mask))
- + ((static_cast<double>(data[2]) / static_cast<double>(cpp_dec_float_elem_mask)) / static_cast<double>(cpp_dec_float_elem_mask));
+ // Establish the upper bound of limbs for extracting the double.
+ const int max_elem_in_double_count = static_cast<int>(static_cast<boost::int32_t>(std::numeric_limits<double>::digits10) / cpp_dec_float_elem_digits10)
+ + (static_cast<int>(static_cast<boost::int32_t>(std::numeric_limits<double>::digits10) % cpp_dec_float_elem_digits10) != 0 ? 1 : 0)
+ + 1;
+
+ // And make sure this upper bound stays within bounds of the elems.
+ const std::size_t max_elem_extract_count = static_cast<std::size_t>((std::min)(static_cast<boost::int32_t>(max_elem_in_double_count), cpp_dec_float_elem_number));
+
+ // Extract into the mantissa the first limb, extracted as a double.
+ mantissa = static_cast<double>(data[0]);
+ double scale = 1.0;
+
+ // Extract the rest of the mantissa piecewise from the limbs.
+ for(std::size_t i = 1u; i < max_elem_extract_count; i++)
+ {
+ scale /= static_cast<double>(cpp_dec_float_elem_mask);
+ mantissa += (static_cast<double>(data[i]) * scale);
+ }
 
    mantissa /= static_cast<double>(p10);
 


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