Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73720 - in sandbox/e_float: boost/e_float libs/e_float/src/e_float libs/e_float/src/e_float/efx libs/e_float/src/e_float/gmp libs/e_float/src/e_float/mpfr libs/e_float/test/real/cases
From: e_float_at_[hidden]
Date: 2011-08-13 16:20:53


Author: christopher_kormanyos
Date: 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
New Revision: 73720
URL: http://svn.boost.org/trac/boost/changeset/73720

Log:
- Unified e_float's min/max values within e_float's base class.
- Cleaned up the overflow/underflow tests.
Text files modified:
   sandbox/e_float/boost/e_float/e_float_base.hpp | 4 +-
   sandbox/e_float/boost/e_float/e_float_efx.hpp | 14 +++++------
   sandbox/e_float/boost/e_float/e_float_gmp.hpp | 15 +++++------
   sandbox/e_float/boost/e_float/e_float_mpfr.hpp | 15 +++++------
   sandbox/e_float/libs/e_float/src/e_float/e_float_base.cpp | 48 +++++++++++++++++++++++++++++++++++-----
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 14 -----------
   sandbox/e_float/libs/e_float/src/e_float/gmp/e_float_gmp.cpp | 14 -----------
   sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp | 18 ---------------
   sandbox/e_float/libs/e_float/test/real/cases/test_case_0000x_overflow_underflow.cpp | 40 ++++++++++++--------------------
   9 files changed, 79 insertions(+), 103 deletions(-)

Modified: sandbox/e_float/boost/e_float/e_float_base.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_base.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_base.hpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -59,8 +59,8 @@
     // Specific special values.
     virtual const e_float& my_value_nan(void) const = 0;
     virtual const e_float& my_value_inf(void) const = 0;
- virtual const e_float& my_value_max(void) const = 0;
- virtual const e_float& my_value_min(void) const = 0;
+ const e_float& my_value_max(void) const;
+ const e_float& my_value_min(void) const;
 
     virtual void precision(const INT32) = 0;
 

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-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -25,13 +25,13 @@
     class e_float : public ::e_float_base
     {
     public:
- static const INT32 ef_radix = static_cast<INT32>(10);
- static const INT32 ef_digits = ef_digits10;
+ static const INT32 ef_radix = static_cast<INT32>(10);
+ static const INT32 ef_digits = ef_digits10;
 
- static const INT64 ef_max_exp = static_cast<INT64>(+9223372036854775795LL);
- static const INT64 ef_min_exp = static_cast<INT64>(-9223372036854775795LL);
- static const INT64 ef_max_exp10 = static_cast<INT64>(+3063937869882635616LL); // Approx. [ef_max_exp / log10(2)], also an even multiple of 8
- static const INT64 ef_min_exp10 = static_cast<INT64>(-3063937869882635616LL);
+ static const INT64 ef_max_exp = static_cast<INT64>(+9223372036854775795LL);
+ static const INT64 ef_min_exp = static_cast<INT64>(-9223372036854775795LL);
+ static const INT64 ef_max_exp10 = static_cast<INT64>(+3063937869882635616LL); // Approx. [ef_max_exp / log10(2)], also an even multiple of 8
+ static const INT64 ef_min_exp10 = static_cast<INT64>(-3063937869882635616LL);
 
       static const INT32 ef_elem_digits10 = static_cast<INT32>(8);
 
@@ -100,8 +100,6 @@
       // Specific special values.
       virtual const e_float& my_value_nan(void) const;
       virtual const e_float& my_value_inf(void) const;
- virtual const e_float& my_value_max(void) const;
- virtual const e_float& my_value_min(void) const;
 
       virtual void precision(const INT32 prec_digits);
 

Modified: sandbox/e_float/boost/e_float/e_float_gmp.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_gmp.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_gmp.hpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -21,6 +21,7 @@
   #endif
 
   #include <cmath>
+ #include <climits>
   #include <string>
 
   #if defined(__GNUC__)
@@ -57,16 +58,16 @@
     class e_float : public ::e_float_base
     {
     public:
- static const INT32 ef_digits = static_cast<INT32>(((static_cast<INT64>(ef_digits10) * 3322LL) + 500LL) / 1000LL);
+ static const INT32 ef_digits = static_cast<INT32>((static_cast<signed long long>(ef_digits10) * 2136LL) / 643LL);
       static const INT32 ef_radix = static_cast<INT32>(2);
 
- static const INT64 ef_max_exp = static_cast<INT64>(+2147483640LL);
- static const INT64 ef_min_exp = static_cast<INT64>(-2147483640LL);
- static const INT64 ef_max_exp10 = static_cast<INT64>(+646456990LL);
- static const INT64 ef_min_exp10 = static_cast<INT64>(-646456990LL);
+ static const INT64 ef_max_exp = static_cast<INT64>(LONG_MAX - 8LL); // TBD: Ensure INT64 >= long
+ static const INT64 ef_min_exp = static_cast<INT64>(LONG_MIN + 8LL); // TBD: Ensure INT64 >= long
+ static const INT64 ef_max_exp10 = static_cast<INT64>((static_cast<signed long long>(ef_max_exp) * 643LL) / 2136LL);
+ static const INT64 ef_min_exp10 = static_cast<INT64>((static_cast<signed long long>(ef_min_exp) * 643LL) / 2136LL);
 
     private:
- static const INT32 ef_digits2 = static_cast<INT32>(((static_cast<INT64>(ef_max_digits10) * 3322LL) + 500LL) / 1000LL);
+ static const INT32 ef_digits2 = static_cast<INT32>((static_cast<signed long long>(ef_max_digits10) * 2136LL) / 643LL);
 
       typedef enum enum_fpclass
       {
@@ -115,8 +116,6 @@
       // Specific special values.
       virtual const e_float& my_value_nan(void) const;
       virtual const e_float& my_value_inf(void) const;
- virtual const e_float& my_value_max(void) const;
- virtual const e_float& my_value_min(void) const;
 
       virtual void precision(const INT32 prec_digits);
 

Modified: sandbox/e_float/boost/e_float/e_float_mpfr.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_mpfr.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_mpfr.hpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -13,6 +13,7 @@
 
   #include <cmath>
   #include <string>
+ #include <climits>
 
   #if defined(__GNUC__)
     #include <tr1/array>
@@ -65,16 +66,16 @@
     class e_float : public ::e_float_base
     {
     public:
- static const INT32 ef_digits = static_cast<INT32>(((static_cast<INT64>(ef_digits10) * 3322LL) + 500LL) / 1000LL);
+ static const INT32 ef_digits = static_cast<INT32>((static_cast<signed long long>(ef_digits10) * 2136LL) / 643LL);
       static const INT32 ef_radix = 2;
 
- static const INT64 ef_max_exp = static_cast<INT64>(+1073741822LL);
- static const INT64 ef_min_exp = static_cast<INT64>(-1073741822LL);
- static const INT64 ef_max_exp10 = static_cast<INT64>(+323228496LL);
- static const INT64 ef_min_exp10 = static_cast<INT64>(-323228496LL);
+ static const INT64 ef_max_exp = static_cast<INT64>(LONG_MAX / static_cast<signed long>(2L)); // TBD: Ensure INT64 >= long
+ static const INT64 ef_min_exp = static_cast<INT64>(LONG_MIN / static_cast<signed long>(2L)); // TBD: Ensure INT64 >= long
+ static const INT64 ef_max_exp10 = static_cast<INT64>((static_cast<signed long long>(ef_max_exp) * 643LL) / 2136LL);
+ static const INT64 ef_min_exp10 = static_cast<INT64>((static_cast<signed long long>(ef_min_exp) * 643LL) / 2136LL);
 
     private:
- static const INT32 ef_digits2 = static_cast<INT32>(((static_cast<INT64>(ef_max_digits10) * 3322LL) + 500LL) / 1000LL);
+ static const INT32 ef_digits2 = static_cast<INT32>((static_cast<signed long long>(ef_max_digits10) * 2136LL) / 643LL);
       ::mpfr_t rop;
 
     public:
@@ -108,8 +109,6 @@
       // Specific special values.
       virtual const e_float& my_value_nan(void) const;
       virtual const e_float& my_value_inf(void) const;
- virtual const e_float& my_value_max(void) const;
- virtual const e_float& my_value_min(void) const;
 
       virtual void precision(const INT32) { }
 

Modified: sandbox/e_float/libs/e_float/src/e_float/e_float_base.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/e_float_base.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/e_float_base.cpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -45,6 +45,20 @@
   return is;
 }
 
+const e_float& e_float_base::my_value_max(void) const
+{
+ static const std::string str_max = std::string("9." + std::string(static_cast<std::size_t>(ef_max_digits10), static_cast<char>('9')))
+ + std::string("e+" + Util::lexical_cast(std::numeric_limits<e_float>::max_exponent10));
+ static const e_float val_max(str_max);
+ return val_max;
+}
+
+const e_float& e_float_base::my_value_min(void) const
+{
+ static const e_float val_min("1.0e" + Util::lexical_cast(std::numeric_limits<e_float>::min_exponent10));
+ return val_min;
+}
+
 e_float& e_float_base::add_signed_long_long(const signed long long n)
 {
   if(n < static_cast<signed long long>(0))
@@ -72,7 +86,9 @@
 
   mul_unsigned_long_long((!b_neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n));
 
- if(b_neg) { negate(); } return static_cast<e_float&>(*this);
+ if(b_neg) { negate(); }
+
+ return static_cast<e_float&>(*this);
 }
 
 e_float& e_float_base::div_signed_long_long(const signed long long n)
@@ -81,7 +97,9 @@
 
   div_unsigned_long_long((!b_neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n));
 
- if(b_neg) { negate(); } return static_cast<e_float&>(*this);
+ if(b_neg) { negate(); }
+
+ return static_cast<e_float&>(*this);
 }
 
 void e_float_base::wr_string(std::string& str, std::ostream& os) const
@@ -90,11 +108,30 @@
   const std::ios::fmtflags my_flags = os.flags();
 
   // Obtain the showpos flag.
- const bool my_showpos = ((my_flags & std::ios::showpos) != static_cast<std::ios::fmtflags>(0u));
+ const bool my_showpos = ((my_flags & std::ios::showpos) != static_cast<std::ios::fmtflags>(0u));
+ const bool my_uppercase = ((my_flags & std::ios::uppercase) != static_cast<std::ios::fmtflags>(0u));
 
   // Handle INF and NaN.
- if(isnan()) { str = ((!isneg()) ? (my_showpos ? std::string("+INF") : std::string("INF")) : std::string("-INF")); return; }
- if(isinf()) { str = "INF"; return; }
+ if(!isfinite())
+ {
+ if(isinf())
+ {
+ if(my_uppercase)
+ {
+ str = ((!isneg()) ? (my_showpos ? std::string("+INF") : std::string("INF")) : std::string("-INF"));
+ }
+ else
+ {
+ str = ((!isneg()) ? (my_showpos ? std::string("+inf") : std::string("inf")) : std::string("-inf"));
+ }
+ }
+ else
+ {
+ str = (my_uppercase ? std::string("NAN") : std::string("nan"));
+ }
+
+ return;
+ }
 
   // Get the base-10 exponent.
   INT64 my_exp = get_order_exact();
@@ -175,7 +212,6 @@
   get_output_string(str, my_exp, the_number_of_digits_i_want_from_e_float);
 
   // Obtain additional format information.
- const bool my_uppercase = ((my_flags & std::ios::uppercase) != static_cast<std::ios::fmtflags>(0u));
   const bool my_showpoint = ((my_flags & std::ios::showpoint) != static_cast<std::ios::fmtflags>(0u));
 
   // Write the output string in the desired format.

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-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -1528,20 +1528,6 @@
   return inf;
 }
 
-const efx::e_float& efx::e_float::my_value_max(void) const
-{
- static const INT64 exp10_max = std::numeric_limits<e_float>::max_exponent10;
- static const e_float val("1E" + Util::lexical_cast(exp10_max));
- return val;
-}
-
-const efx::e_float& efx::e_float::my_value_min(void) const
-{
- static const INT64 exp10_min = std::numeric_limits<e_float>::min_exponent10;
- static const e_float val("1E" + Util::lexical_cast(exp10_min));
- return val;
-}
-
 INT64 efx::e_float::get_order_fast(void) const
 {
   if(iszero())

Modified: sandbox/e_float/libs/e_float/src/e_float/gmp/e_float_gmp.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/gmp/e_float_gmp.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/gmp/e_float_gmp.cpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -708,20 +708,6 @@
   return inf;
 }
 
-const gmp::e_float& gmp::e_float::my_value_max(void) const
-{
- static const INT64 exp10_max = std::numeric_limits<e_float>::max_exponent10;
- static const e_float val("1E" + Util::lexical_cast(exp10_max));
- return val;
-}
-
-const gmp::e_float& gmp::e_float::my_value_min(void) const
-{
- static const INT64 exp10_min = std::numeric_limits<e_float>::min_exponent10;
- static const e_float val("1E" + Util::lexical_cast(exp10_min));
- return val;
-}
-
 e_float& gmp::e_float::negate(void) { ::mpf_neg(rop, rop); return *this; }
 
 e_float& gmp::e_float::operator++(void) { ::mpf_add_ui(rop, rop, static_cast<unsigned long>(1u)); return *this; }

Modified: sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -160,24 +160,6 @@
   return inf;
 }
 
-const mpfr::e_float& mpfr::e_float::my_value_max(void) const
-{
- static const INT64 exp10_max = std::numeric_limits<e_float>::max_exponent10;
-
- static const e_float val("1E" + Util::lexical_cast(exp10_max));
-
- return val;
-}
-
-const mpfr::e_float& mpfr::e_float::my_value_min(void) const
-{
- static const INT64 exp10_min = std::numeric_limits<e_float>::min_exponent10;
-
- static const e_float val("1E" + Util::lexical_cast(exp10_min));
-
- return val;
-}
-
 mpfr::e_float& mpfr::e_float::operator=(const e_float& v)
 {
   static_cast<void>(::mpfr_set(rop, v.rop, GMP_RNDN));

Modified: sandbox/e_float/libs/e_float/test/real/cases/test_case_0000x_overflow_underflow.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/test/real/cases/test_case_0000x_overflow_underflow.cpp (original)
+++ sandbox/e_float/libs/e_float/test/real/cases/test_case_0000x_overflow_underflow.cpp 2011-08-13 16:20:52 EDT (Sat, 13 Aug 2011)
@@ -18,6 +18,7 @@
     class TestCaseOverflowUnderflowBase : public TestCaseReal
     {
     protected:
+ static const INT32 kmax = static_cast<INT32>(1000);
 
       mutable bool my_test_result;
 
@@ -87,19 +88,16 @@
         data.push_back(y);
 
         INT32 k;
- for(k = static_cast<INT32>(0); k < static_cast<INT32>(1000); k++)
+ for(k = static_cast<INT32>(0); k < kmax; k++)
         {
           y = y * y;
 
           data.push_back(y);
 
- if(ef::isinf(y))
- {
- break;
- }
+ if(ef::isinf(y)) { break; }
         }
 
- my_test_result = (k > static_cast<INT32>(1)) && (k < static_cast<INT32>(1000));
+ my_test_result = (k > static_cast<INT32>(1)) && (k < kmax);
       }
     };
 
@@ -123,16 +121,13 @@
         data.push_back(y);
 
         INT32 k;
- for(k = static_cast<INT32>(0); k < static_cast<INT32>(1000); k++)
+ for(k = static_cast<INT32>(0); k < kmax; k++)
         {
           y = y * y;
 
           data.push_back(y);
 
- if(ef::iszero(y))
- {
- break;
- }
+ if(ef::iszero(y)) { break; }
         }
 
         my_test_result = (k > static_cast<INT32>(1)) && (k < static_cast<INT32>(1000));
@@ -159,19 +154,17 @@
         data.push_back(y);
 
         INT32 k;
- for(k = static_cast<INT32>(0); k < static_cast<INT32>(1000); k++)
+
+ for(k = static_cast<INT32>(0); k < kmax; k++)
         {
- y = y * static_cast<INT32>(2);
+ y = y * static_cast<INT32>(3);
 
           data.push_back(y);
 
- if(ef::isinf(y))
- {
- break;
- }
+ if(ef::isinf(y)) { break; }
         }
 
- my_test_result = (k > static_cast<INT32>(1)) && (k < static_cast<INT32>(1000));
+ my_test_result = (k > static_cast<INT32>(1)) && (k < kmax);
       }
     };
 
@@ -195,19 +188,16 @@
         data.push_back(y);
 
         INT32 k;
- for(k = static_cast<INT32>(0); k < static_cast<INT32>(1000); k++)
+ for(k = static_cast<INT32>(0); k < kmax; k++)
         {
- y = y / static_cast<INT32>(2);
+ y = y / static_cast<INT32>(3);
 
           data.push_back(y);
 
- if(ef::iszero(y))
- {
- break;
- }
+ if(ef::iszero(y)) { break; }
         }
 
- my_test_result = (k > static_cast<INT32>(1)) && (k < static_cast<INT32>(1000));
+ my_test_result = (k > static_cast<INT32>(1)) && (k < kmax);
       }
     };
 


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