Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85314 - trunk/boost/multiprecision/detail
From: john_at_[hidden]
Date: 2013-08-12 07:58:17


Author: johnmaddock
Date: 2013-08-12 07:58:17 EDT (Mon, 12 Aug 2013)
New Revision: 85314
URL: http://svn.boost.org/trac/boost/changeset/85314

Log:
Fix overflow bug.

Text files modified:
   trunk/boost/multiprecision/detail/float_string_cvt.hpp | 19 ++++++++++++++++---
   1 files changed, 16 insertions(+), 3 deletions(-)

Modified: trunk/boost/multiprecision/detail/float_string_cvt.hpp
==============================================================================
--- trunk/boost/multiprecision/detail/float_string_cvt.hpp Mon Aug 12 07:56:45 2013 (r85313)
+++ trunk/boost/multiprecision/detail/float_string_cvt.hpp 2013-08-12 07:58:17 EDT (Mon, 12 Aug 2013) (r85314)
@@ -91,8 +91,21 @@
       eval_log10(t, b);
       eval_floor(t, t);
       eval_convert_to(&expon, t);
- eval_pow(t, ten, -expon);
- eval_multiply(t, b);
+ if(-expon > std::numeric_limits<number<Backend> >::max_exponent10 - 3)
+ {
+ int e = -expon / 2;
+ Backend t2;
+ eval_pow(t2, ten, e);
+ eval_multiply(t, t2, b);
+ eval_multiply(t, t2);
+ if(expon & 1)
+ eval_multiply(t, ten);
+ }
+ else
+ {
+ eval_pow(t, ten, -expon);
+ eval_multiply(t, b);
+ }
       //
       // Make sure we're between [1,10) and adjust if not:
       //
@@ -137,7 +150,7 @@
          if((cdigit == 5) && (t.compare(ui_type(0)) == 0))
          {
             // Bankers rounding:
- if((*result.rend() - '0') & 1)
+ if((*result.rbegin() - '0') & 1)
             {
                round_string_up_at(result, result.size() - 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