|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75597 - sandbox/big_number/boost/multiprecision
From: john_at_[hidden]
Date: 2011-11-21 14:20:38
Author: johnmaddock
Date: 2011-11-21 14:20:35 EST (Mon, 21 Nov 2011)
New Revision: 75597
URL: http://svn.boost.org/trac/boost/changeset/75597
Log:
Fix showpos support.
Text files modified:
sandbox/big_number/boost/multiprecision/cpp_float.hpp | 3 +++
sandbox/big_number/boost/multiprecision/gmp.hpp | 8 ++++++++
sandbox/big_number/boost/multiprecision/mpfr.hpp | 8 ++++++++
3 files changed, 19 insertions(+), 0 deletions(-)
Modified: sandbox/big_number/boost/multiprecision/cpp_float.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_float.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_float.hpp 2011-11-21 14:20:35 EST (Mon, 21 Nov 2011)
@@ -1644,6 +1644,7 @@
bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
bool showpoint = (f & std::ios_base::showpoint) == std::ios_base::showpoint;
+ bool shopos = (f & std::ios_base::showpos) == std::ios_base::showpos;
std::string str;
boost::int64_t my_exp = order();
@@ -1756,6 +1757,8 @@
}
if(isneg())
str.insert(0, 1, '-');
+ else if(shopos)
+ str.insert(0, 1, '+');
return str;
}
Modified: sandbox/big_number/boost/multiprecision/gmp.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/gmp.hpp (original)
+++ sandbox/big_number/boost/multiprecision/gmp.hpp 2011-11-21 14:20:35 EST (Mon, 21 Nov 2011)
@@ -164,6 +164,7 @@
bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
bool showpoint = (f & std::ios_base::showpoint) == std::ios_base::showpoint;
+ bool showpos = (f & std::ios_base::showpos) == std::ios_base::showpos;
std::string result;
mp_exp_t e;
@@ -173,7 +174,12 @@
const char* ps = mpf_get_str (0, &e, 10, static_cast<std::size_t>(digits), m_data);
std::ptrdiff_t sl = std::strlen(ps);
if(sl == 0)
+ {
+ result = scientific ? "0.0e0" : showpoint ? "0.0" : "0";
+ if(showpos)
+ result.insert(0, 1, '+');
return "0";
+ }
if(*ps == '-')
--sl; // number of digits excluding sign.
result = ps;
@@ -209,6 +215,8 @@
if(e)
result += "e" + lexical_cast<std::string>(e);
}
+ if(shopos && (str[0] != '-'))
+ str.insert(0, 1, '+');
mp_get_memory_functions(&alloc_func_ptr, &realloc_func_ptr, &free_func_ptr);
(*free_func_ptr)((void*)ps, std::strlen(ps) + 1);
return result;
Modified: sandbox/big_number/boost/multiprecision/mpfr.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/mpfr.hpp (original)
+++ sandbox/big_number/boost/multiprecision/mpfr.hpp 2011-11-21 14:20:35 EST (Mon, 21 Nov 2011)
@@ -161,6 +161,7 @@
bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
bool showpoint = (f & std::ios_base::showpoint) == std::ios_base::showpoint;
+ bool showpos = (f & std::ios_base::showpos) == std::ios_base::showpos;
std::string result;
mp_exp_t e;
@@ -168,7 +169,12 @@
std::ptrdiff_t sl = std::strlen(ps);
int chars = sl;
if(sl == 0)
+ {
+ result = scientific ? "0.0e0" : showpoint ? "0.0" : "0";
+ if(showpos)
+ result.insert(0, 1, '+');
return "0";
+ }
while(ps[chars-1] == '0')
--chars;
ps[chars] = 0;
@@ -209,6 +215,8 @@
if(e)
result += "e" + lexical_cast<std::string>(e);
}
+ if(shopos && (str[0] != '-'))
+ str.insert(0, 1, '+');
mpfr_free_str(ps);
return result;
}
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