Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73450 - in sandbox/e_float: boost/e_float libs/e_float/src/e_float/efx
From: e_float_at_[hidden]
Date: 2011-07-30 15:26:48


Author: christopher_kormanyos
Date: 2011-07-30 15:26:48 EDT (Sat, 30 Jul 2011)
New Revision: 73450
URL: http://svn.boost.org/trac/boost/changeset/73450

Log:
- Refined write functions to std::ostream.
Text files modified:
   sandbox/e_float/boost/e_float/e_float_efx.hpp | 2 +-
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 39 +++++++++++++++++++++------------------
   2 files changed, 22 insertions(+), 19 deletions(-)

Modified: sandbox/e_float/boost/e_float/e_float_efx.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_efx.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_efx.hpp 2011-07-30 15:26:48 EDT (Sat, 30 Jul 2011)
@@ -181,7 +181,7 @@
     private:
       virtual void wr_string(std::string& str, std::ostream& os) const;
       void wr_string_scientific(std::string& str, const INT64 my_exp, const std::size_t os_precision, const bool my_showpos, const bool my_uppercase) const;
- void wr_string_fixed (std::string& str, const INT64 my_exp, const std::size_t os_precision, const bool my_showpos, const bool my_showpoint, const bool use_pad_when_above_one = true) const;
+ void wr_string_fixed (std::string& str, const INT64 my_exp, const std::size_t os_precision, const bool my_showpos, const bool my_showpoint, const bool trim_trailing_zeros = false) const;
       virtual bool rd_string(const char* const s);
     };
   }

Modified: sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp 2011-07-30 15:26:48 EDT (Sat, 30 Jul 2011)
@@ -1592,7 +1592,7 @@
     }
     else if(use_fixed)
     {
- wr_string_fixed(str, my_exp, os_precision, my_showpos, my_showpoint, false);
+ wr_string_fixed(str, my_exp, os_precision, my_showpos, my_showpoint, true);
     }
   }
 }
@@ -1641,7 +1641,7 @@
   }
 }
 
-void efx::e_float::wr_string_fixed(std::string& str, const INT64 my_exp, const std::size_t os_precision, const bool my_showpos, const bool my_showpoint, const bool use_pad_when_above_one) const
+void efx::e_float::wr_string_fixed(std::string& str, const INT64 my_exp, const std::size_t os_precision, const bool my_showpos, const bool my_showpoint, const bool trim_trailing_zeros) const
 {
   const std::size_t str_len = str.length();
 
@@ -1663,30 +1663,33 @@
   }
   else
   {
- // Insert the decimal point, but only if showpoint is set
- // and the string does not represent a whole number.
+ // Insert the decimal point.
     const std::size_t my_exp_plus_one = static_cast<std::size_t>(my_exp + 1);
 
- if((!my_showpoint) && (my_exp_plus_one == str.length()))
+ str.insert(my_exp_plus_one, ".");
+
+ // Zero-extend the string to the given precision if necessary.
+ const INT64 n_pad = static_cast<INT64>(os_precision) - static_cast<INT64>(static_cast<INT64>(str_len) - (my_exp + 1));
+
+ if(n_pad > static_cast<INT64>(0))
     {
+ str.insert(str.end(), static_cast<std::size_t>(n_pad), static_cast<char>('0'));
     }
- else
- {
- str.insert(static_cast<std::size_t>(my_exp + 1), ".");
-
- // Zero-extend the string to the given precision if necessary.
- if(use_pad_when_above_one)
- {
- const INT64 n_pad = static_cast<INT64>(os_precision) - static_cast<INT64>(static_cast<INT64>(str_len) - (my_exp + 1));
+ }
 
- if(n_pad > static_cast<INT64>(0))
- {
- str.insert(str.end(), static_cast<std::size_t>(n_pad), static_cast<char>('0'));
- }
- }
+ if(trim_trailing_zeros)
+ {
+ while(str.back() == static_cast<char>('0'))
+ {
+ str.pop_back();
     }
   }
 
+ if((str.back() == static_cast<char>('.')) && (!my_showpoint))
+ {
+ str.pop_back();
+ }
+
   // Append the sign.
   if(isneg())
   {


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