|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77775 - sandbox/big_number/boost/multiprecision
From: john_at_[hidden]
Date: 2012-04-05 04:22:24
Author: johnmaddock
Date: 2012-04-05 04:22:20 EDT (Thu, 05 Apr 2012)
New Revision: 77775
URL: http://svn.boost.org/trac/boost/changeset/77775
Log:
Add static assert to protect multiplication algorithm from excessive limb counts.
Text files modified:
sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
Modified: sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp 2012-04-05 04:22:20 EDT (Thu, 05 Apr 2012)
@@ -2208,6 +2208,14 @@
template <unsigned Digits10>
void cpp_dec_float<Digits10>::mul_loop_uv(const boost::uint32_t* const u, const boost::uint32_t* const v, boost::uint32_t* const w, const boost::int32_t p)
{
+ //
+ // There is a limit on how many limbs this algorithm can handle without dropping digits
+ // due to overflow in the carry, it is:
+ //
+ // FLOOR( (2^64 - 1) / (10^8 * 10^8) ) == 1844
+ //
+ BOOST_STATIC_ASSERT_MSG(mp_elem_number < 1800, "Too many limbs in the data type for the multiplication algorithm - unsupported precision in cpp_dec_float.");
+
boost::uint64_t carry = static_cast<boost::uint64_t>(0u);
for(boost::int32_t j = static_cast<boost::int32_t>(p - 1u); j >= static_cast<boost::int32_t>(0); j--)
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