Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73461 - in sandbox/e_float/libs/e_float: build src/e_float/efx test/real test/real/cases
From: e_float_at_[hidden]
Date: 2011-07-31 08:05:39


Author: christopher_kormanyos
Date: 2011-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
New Revision: 73461
URL: http://svn.boost.org/trac/boost/changeset/73461

Log:
- Added some test cases for ostream write functions.
Added:
   sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp (contents, props changed)
Text files modified:
   sandbox/e_float/libs/e_float/build/MakefileFiles.gmk | 3 ++-
   sandbox/e_float/libs/e_float/build/e_float.vcxproj | 3 ++-
   sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters | 9 ++++++---
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 6 ++++--
   sandbox/e_float/libs/e_float/test/real/test_real.cpp | 2 ++
   5 files changed, 16 insertions(+), 7 deletions(-)

Modified: sandbox/e_float/libs/e_float/build/MakefileFiles.gmk
==============================================================================
--- sandbox/e_float/libs/e_float/build/MakefileFiles.gmk (original)
+++ sandbox/e_float/libs/e_float/build/MakefileFiles.gmk 2011-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -51,7 +51,7 @@
 FILES_EXAMPLES = ../example/example_001_basic_usage_real \
                   ../example/example_002_basic_usage_imag \
                   ../example/example_005_recursive_trapezoid_integral \
- ../example/example_008_guass_laguerre
+ ../example/example_008_gauss_laguerre
 
 #
 # Test files
@@ -69,6 +69,7 @@
 #
 FILES_TEST_REAL = ../test/real/test_real \
                   ../test/real/cases/test_case_0000x_overflow_underflow \
+ ../test/real/cases/test_case_0000y_write_to_ostream \
                   ../test/real/cases/test_case_00011_various_elem_math \
                   ../test/real/cases/test_case_00021_bernoulli \
                   ../test/real/cases/test_case_00051_factorial \

Modified: sandbox/e_float/libs/e_float/build/e_float.vcxproj
==============================================================================
--- sandbox/e_float/libs/e_float/build/e_float.vcxproj (original)
+++ sandbox/e_float/libs/e_float/build/e_float.vcxproj 2011-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -768,7 +768,7 @@
     <ClCompile Include="..\example\example_001_basic_usage_real.cpp" />
     <ClCompile Include="..\example\example_002_basic_usage_imag.cpp" />
     <ClCompile Include="..\example\example_005_recursive_trapezoid_integral.cpp" />
- <ClCompile Include="..\example\example_008_guass_laguerre.cpp" />
+ <ClCompile Include="..\example\example_008_gauss_laguerre.cpp" />
     <ClCompile Include="..\src\e_float\e_float.cpp" />
     <ClCompile Include="..\src\e_float\e_float_base.cpp" />
     <ClCompile Include="..\src\e_float\efx\e_float_efx.cpp">
@@ -1033,6 +1033,7 @@
     <ClCompile Include="..\test\imag\cases\test_case_02911_z_zeta_crit_strip.cpp" />
     <ClCompile Include="..\test\imag\test_imag.cpp" />
     <ClCompile Include="..\test\real\cases\test_case_0000x_overflow_underflow.cpp" />
+ <ClCompile Include="..\test\real\cases\test_case_0000y_write_to_ostream.cpp" />
     <ClCompile Include="..\test\real\cases\test_case_00011_various_elem_math.cpp" />
     <ClCompile Include="..\test\real\cases\test_case_00021_bernoulli.cpp" />
     <ClCompile Include="..\test\real\cases\test_case_00051_factorial.cpp" />

Modified: sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters
==============================================================================
--- sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters (original)
+++ sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters 2011-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -94,9 +94,6 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
- <ClCompile Include="..\example\example_008_guass_laguerre.cpp">
- <Filter>libs\e_float\example</Filter>
- </ClCompile>
     <ClCompile Include="..\src\e_float\e_float.cpp">
       <Filter>libs\e_float\src\e_float</Filter>
     </ClCompile>
@@ -373,6 +370,12 @@
     <ClCompile Include="..\test\imag\cases\test_case_02911_z_zeta_crit_strip.cpp">
       <Filter>libs\e_float\test\imag\cases</Filter>
     </ClCompile>
+ <ClCompile Include="..\test\real\cases\test_case_0000y_write_to_ostream.cpp">
+ <Filter>libs\e_float\test\real\cases</Filter>
+ </ClCompile>
+ <ClCompile Include="..\example\example_008_gauss_laguerre.cpp">
+ <Filter>libs\e_float\example</Filter>
+ </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\src\functions\gamma\gamma_util.h">

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-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -42,8 +42,10 @@
   }
   os_float_filed_type;
 
- // Emphasize: This template class can be used with native
- // floating-point types like float, double and long double.
+ // Emphasize: This template class can be used with native floating-point
+ // types like float, double and 10-byte long double. It will need to be
+ // extended for 16-byte long double because the mantissa will no longer
+ // fit in UINT64.
   template<typename native_float_type>
   class native_float_parts : private Util::noncopyable
   {

Added: sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp
==============================================================================
--- (empty file)
+++ sandbox/e_float/libs/e_float/test/real/cases/test_case_0000y_write_to_ostream.cpp 2011-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -0,0 +1,221 @@
+
+// Copyright Christopher Kormanyos 2002 - 2011.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// This work is based on an earlier work:
+// "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
+// in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
+
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+#include <e_float/e_float_functions.hpp>
+#include "../test_case_real.h"
+
+namespace
+{
+ std::string make_pi_string(const std::size_t number_of_digits)
+ {
+ // 1100 digits of pi
+ static const std::string str =
+ std::string("3.")
+ + std::string("1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679")
+ + std::string("8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196")
+ + std::string("4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273")
+ + std::string("7245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094")
+ + std::string("3305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912")
+ + std::string("9833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132")
+ + std::string("0005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235")
+ + std::string("4201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859")
+ + std::string("5024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303")
+ + std::string("5982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989")
+ + std::string("3809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913152")
+ ;
+
+ std::string str_pi(str.begin(), str.begin() + (number_of_digits + 3u));
+
+ bool b_round_up = (str_pi.back() >= static_cast<char>('5'));
+ str_pi.pop_back();
+
+ if(b_round_up)
+ {
+ std::string::iterator it = str_pi.end() - 1u;
+
+ bool b_break = false;
+
+ while(!b_break)
+ {
+ if(*it == static_cast<char>('9'))
+ {
+ *it = static_cast<char>('0');
+ }
+ else
+ {
+ *it = static_cast<char>(*it + static_cast<char>(1));
+ b_break = true;
+ }
+
+ --it;
+ }
+ }
+
+ return str_pi;
+ }
+}
+
+namespace test
+{
+ namespace real
+ {
+ class TestCaseWriteToOstreamBase : public TestCaseReal
+ {
+ protected:
+
+ mutable bool my_test_result;
+
+ TestCaseWriteToOstreamBase() : my_test_result(false) { }
+
+ private:
+
+ virtual const std::vector<e_float>& control_data(void) const
+ {
+ static const std::vector<e_float> dummy; return dummy;
+ }
+
+ public:
+
+ virtual ~TestCaseWriteToOstreamBase() { }
+
+ virtual bool execute(const bool b_write_output) const
+ {
+ std::cout << name() << " : ";
+
+ std::vector<e_float> e_float_data;
+
+ // Calculate the e_float test data.
+ e_float_test(e_float_data);
+
+ // Optionally write the e_float test data to an output file.
+ if(b_write_output)
+ {
+ if(!write_output_file(e_float_data))
+ {
+ std::cout << "Can not write output: FAIL" << std::endl;
+ return false;
+ }
+ }
+
+ if(my_test_result)
+ {
+ std::cout << "Numerical compare OK: PASS" << std::endl;
+ return true;
+ }
+ else
+ {
+ std::cout << "Numerical compare not OK: FAIL" << std::endl;
+ return false;
+ }
+ }
+ };
+
+ class TestCase_case_00006_write_os_floatfield_fixed : public TestCaseWriteToOstreamBase
+ {
+ public:
+ TestCase_case_00006_write_os_floatfield_fixed() { }
+ virtual ~TestCase_case_00006_write_os_floatfield_fixed() { }
+ private:
+ virtual const std::string& name(void) const
+ {
+ static const std::string str("TestCase_case_00006_write_os_floatfield_fixed");
+ 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 << std::fixed << std::showpos << std::showpoint << 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::fixed << 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::fixed << std::showpos << std::showpoint << std::setprecision(2) << ef::pi();
+ str = ss.str();
+ data.push_back(e_float(str));
+ my_test_result &= (str == std::string("+3.14"));
+ ss.clear();
+ ss.str("");
+
+ ss << std::fixed << std::showpos << std::showpoint << std::setprecision(10) << ef::pi();
+ str = ss.str();
+ data.push_back(e_float(str));
+ my_test_result &= (str == std::string("+3.1415926536"));
+ ss.clear();
+ ss.str("");
+
+ ss << std::fixed << 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::fixed << std::showpos << std::showpoint << std::setprecision(std::numeric_limits<e_float>::digits10) << 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>::digits10));
+ my_test_result &= (str == (std::string("+") + str_pi));
+ ss.clear();
+ ss.str("");
+
+ ss << std::fixed << std::showpos << std::showpoint << std::setprecision(1000) << ef::pi();
+ str = ss.str();
+ data.push_back(e_float(str));
+ 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 + std::string(1002u - str_pi.length(), static_cast<char>('0')))));
+ ss.clear();
+ ss.str("");
+
+ ss << std::fixed << std::showpos << std::showpoint << std::setprecision(29) << ef::pi() / e_float("1e10");
+ str = ss.str();
+ data.push_back(e_float(str));
+ str_pi = ::make_pi_string(static_cast<std::size_t>(19));
+ str_pi.erase(str_pi.begin() + 1u);
+ my_test_result &= (str == (std::string("+0.") + (std::string(9u, static_cast<char>('0')) + str_pi)));
+ ss.clear();
+ ss.str("");
+
+ ss << std::fixed << std::showpos << std::showpoint << std::setprecision(19) << -ef::pi() * e_float("1e10");
+ str = ss.str();
+ data.push_back(e_float(str));
+ str_pi = ::make_pi_string(static_cast<std::size_t>(29));
+ str_pi.erase(str_pi.begin() + 1u);
+ str_pi.insert(str_pi.begin() + 11u, 1u, static_cast<char>('.'));
+ 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);
+ }
+ }
+}

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-07-31 08:05:38 EDT (Sun, 31 Jul 2011)
@@ -20,6 +20,7 @@
     bool test_case_00002_underflow_mul_x (const bool b_write_output);
     bool test_case_00003_overflow_x_mul_by_n (const bool b_write_output);
     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_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);
@@ -62,6 +63,7 @@
   test_ok &= test::real::test_case_00002_underflow_mul_x (b_write_output);
   test_ok &= test::real::test_case_00003_overflow_x_mul_by_n (b_write_output);
   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_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);


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