|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85420 - trunk/boost/multiprecision/detail
From: john_at_[hidden]
Date: 2013-08-22 08:38:19
Author: johnmaddock
Date: 2013-08-22 08:38:19 EDT (Thu, 22 Aug 2013)
New Revision: 85420
URL: http://svn.boost.org/trac/boost/changeset/85420
Log:
Fix some buglets in decimal rounding.
Text files modified:
trunk/boost/multiprecision/detail/float_string_cvt.hpp | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
Modified: trunk/boost/multiprecision/detail/float_string_cvt.hpp
==============================================================================
--- trunk/boost/multiprecision/detail/float_string_cvt.hpp Thu Aug 22 08:35:25 2013 (r85419)
+++ trunk/boost/multiprecision/detail/float_string_cvt.hpp 2013-08-22 08:38:19 EDT (Thu, 22 Aug 2013) (r85420)
@@ -16,7 +16,7 @@
namespace boost{ namespace multiprecision{ namespace detail{
-inline void round_string_up_at(std::string& s, int pos)
+inline void round_string_up_at(std::string& s, int pos, int& expon)
{
//
// Rounds up a string representation of a number at pos:
@@ -24,14 +24,18 @@
if(pos < 0)
{
s.insert(0, 1, '1');
+ s.erase(s.size() - 1);
+ ++expon;
}
else if(s[pos] == '9')
{
s[pos] = '0';
- round_string_up_at(s, pos - 1);
+ round_string_up_at(s, pos - 1, expon);
}
else
{
+ if((pos == 0) && (s[pos] == '0') && (s.size() == 1))
+ ++expon;
++s[pos];
}
}
@@ -152,12 +156,12 @@
// Bankers rounding:
if((*result.rbegin() - '0') & 1)
{
- round_string_up_at(result, result.size() - 1);
+ round_string_up_at(result, result.size() - 1, expon);
}
}
else if(cdigit >= 5)
{
- round_string_up_at(result, result.size() - 1);
+ round_string_up_at(result, result.size() - 1, expon);
}
}
}
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