$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r73487 - in sandbox/e_float/libs/e_float: src/e_float/efx test/real test/real/cases
From: e_float_at_[hidden]
Date: 2011-08-02 06:10:04
Author: christopher_kormanyos
Date: 2011-08-02 06:10:03 EDT (Tue, 02 Aug 2011)
New Revision: 73487
URL: http://svn.boost.org/trac/boost/changeset/73487
Log:
- Added test case number 8 for ostream-write.
- Improved ostream-write efficiency.
Text files modified: 
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp                      |    34 ++++++-----                             
   sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp |   118 ++++++++++++++++++++++++++++++++++++++++
   sandbox/e_float/libs/e_float/test/real/test_real.cpp                              |     2                                         
   3 files changed, 139 insertions(+), 15 deletions(-)
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-08-02 06:10:03 EDT (Tue, 02 Aug 2011)
@@ -1445,22 +1445,10 @@
   // Extract all of the digits from e_float, beginning with the first data element.
   str = Util::lexical_cast(data[0]);
 
-  // Readjust the exponent based on the width of the leading data element.
+  // Readjust the exponent based on the width of the first data element.
   INT64 my_exp = ((!iszero()) ? static_cast<INT64>((exp + static_cast<INT64>(str.length())) - static_cast<INT64>(1))
                               : static_cast<INT64>(0));
 
-  // Add the remaining digits after the decimal point.
-  for(std::size_t i = static_cast<std::size_t>(1u); i < static_cast<std::size_t>(ef_elem_number); i++)
-  {
-    std::stringstream ss;
-
-    ss << std::setw(static_cast<std::streamsize>(ef_elem_digits10))
-       << std::setfill(static_cast<char>('0'))
-       << data[i];
-
-    str += ss.str();
-  }
-
   // Get the output stream's precision and limit it to max_digits10.
   // Erroneous negative precision will be set to the zero.
   const std::size_t os_precision  = ((os.precision() > std::streamsize(-1)) ? static_cast<std::size_t>(os.precision())
@@ -1488,7 +1476,7 @@
       // Use exponential notation.
       use_scientific = true;
     }
-    else if(my_exp >= (std::min)(static_cast<INT64>(std::numeric_limits<e_float>::digits10), static_cast<INT64>(os_precision)))
+    else if(my_exp >= (std::min)(static_cast<INT64>(std::numeric_limits<e_float>::digits10), (std::max)(static_cast<INT64>(os_precision), static_cast<INT64>(7))))
     {
       // The number is large in magnitude with a large, positive exponent.
       // Use exponential notation.
@@ -1535,7 +1523,23 @@
     }
   }
 
-  // Cut the output to the size of the precision.
+  // Determine the number of elements needed to provide the requested digits from e_float.
+  const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>((the_number_of_digits_i_want_from_e_float / static_cast<std::size_t>(ef_elem_digits10)) + 2u),
+                                                    static_cast<std::size_t>(ef_elem_number));
+
+  // Extract the remaining digits from e_float after the decimal point.
+  for(std::size_t i = static_cast<std::size_t>(1u); i < number_of_elements; i++)
+  {
+    std::stringstream ss;
+
+    ss << std::setw(static_cast<std::streamsize>(ef_elem_digits10))
+       << std::setfill(static_cast<char>('0'))
+       << data[i];
+
+    str += ss.str();
+  }
+
+  // Trim (and round) the output string to the size of the precision.
   round_output_string(str, my_exp, the_number_of_digits_i_want_from_e_float);
 
   // Obtain additional format information.
Modified: sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp	(original)
+++ sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp	2011-08-02 06:10:03 EDT (Tue, 02 Aug 2011)
@@ -317,6 +317,120 @@
       }
     };
 
+    class TestCase_case_00008_write_os_floatfield_not_set : public TestCaseWriteToOstreamBase
+    {
+    public:
+      TestCase_case_00008_write_os_floatfield_not_set() { }
+      virtual ~TestCase_case_00008_write_os_floatfield_not_set() { }
+    private:
+      virtual const std::string& name(void) const
+      {
+        static const std::string str("TestCase_case_00008_write_os_floatfield_not_set");
+        return str;
+      }
+      virtual void e_float_test(std::vector<e_float>& data) const
+      {
+        data.clear();
+
+        my_test_result = true;
+
+        std::string str;
+        std::stringstream ss;
+
+        ss << ef::million();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1000000"));
+        ss.clear();
+        ss.str("");
+
+        ss << e_float(100000000000uLL); // 10^11
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1e+011"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::showpoint << ef::googol();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1.e+100"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::noshowpoint << ef::googol();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1e+100"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::noshowpoint << (static_cast<INT32>(1) / ef::googol());
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1e-100"));
+        ss.clear();
+        ss.str("");
+
+        ss << e_float("1e1234");
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("1e+001234"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::showpoint << ef::eight();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("8."));
+        ss.clear();
+        ss.str("");
+
+        ss << std::noshowpoint << ef::eight();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("8"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::noshowpos << std::noshowpoint << std::setprecision(0) << ef::pi();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("3"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::noshowpos << std::noshowpoint << std::setprecision(0) << (ef::pi() * static_cast<INT32>(100));
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("314"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::showpos << std::showpoint << std::setprecision(1) << ef::pi();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("+3.1"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::showpos << std::showpoint << std::setprecision(20) << ef::pi();
+        str = ss.str();
+        data.push_back(e_float(str));
+        my_test_result &= (str == std::string("+3.14159265358979323846"));
+        ss.clear();
+        ss.str("");
+
+        ss << std::showpos << std::showpoint << std::setprecision(1000) << ef::pi();
+        str = ss.str();
+        data.push_back(e_float(str));
+        std::string str_pi = ::make_pi_string(static_cast<std::size_t>(std::numeric_limits<e_float>::max_digits10));
+        my_test_result &= (str == (std::string("+") + str_pi));
+        ss.clear();
+        ss.str("");
+      }
+    };
+
     bool test_case_00006_write_os_floatfield_fixed(const bool b_write_output)
     {
       return TestCase_case_00006_write_os_floatfield_fixed().execute(b_write_output);
@@ -325,5 +439,9 @@
     {
       return TestCase_case_00007_write_os_floatfield_scientific().execute(b_write_output);
     }
+    bool test_case_00008_write_os_floatfield_not_set(const bool b_write_output)
+    {
+      return TestCase_case_00008_write_os_floatfield_not_set().execute(b_write_output);
+    }
   }
 }
Modified: sandbox/e_float/libs/e_float/test/real/test_real.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/test/real/test_real.cpp	(original)
+++ sandbox/e_float/libs/e_float/test/real/test_real.cpp	2011-08-02 06:10:03 EDT (Tue, 02 Aug 2011)
@@ -22,6 +22,7 @@
     bool test_case_00004_underflow_x_div_by_n          (const bool b_write_output);
     bool test_case_00006_write_os_floatfield_fixed     (const bool b_write_output);
     bool test_case_00007_write_os_floatfield_scientific(const bool b_write_output);
+    bool test_case_00008_write_os_floatfield_not_set   (const bool b_write_output);
     bool test_case_00011_various_elem_math             (const bool b_write_output);
     bool test_case_00021_bernoulli                     (const bool b_write_output);
     bool test_case_00051_factorial                     (const bool b_write_output);
@@ -66,6 +67,7 @@
   test_ok &= test::real::test_case_00004_underflow_x_div_by_n          (b_write_output);
   test_ok &= test::real::test_case_00006_write_os_floatfield_fixed     (b_write_output);
   test_ok &= test::real::test_case_00007_write_os_floatfield_scientific(b_write_output);
+  test_ok &= test::real::test_case_00008_write_os_floatfield_not_set   (b_write_output);
   test_ok &= test::real::test_case_00011_various_elem_math             (b_write_output);
   test_ok &= test::real::test_case_00021_bernoulli                     (b_write_output);
   test_ok &= test::real::test_case_00051_factorial                     (b_write_output);