Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73555 - 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/mpfr libs/e_float/test/real/cases
From: e_float_at_[hidden]
Date: 2011-08-05 15:54:55


Author: christopher_kormanyos
Date: 2011-08-05 15:54:53 EDT (Fri, 05 Aug 2011)
New Revision: 73555
URL: http://svn.boost.org/trac/boost/changeset/73555

Log:
- Made some trivial simplifications in the EFX and MPFR back-ends.
Text files modified:
   sandbox/e_float/boost/e_float/e_float_base.hpp | 2 -
   sandbox/e_float/libs/e_float/src/e_float/e_float_base.cpp | 14 --------
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 8 +--
   sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp | 70 +++++++++------------------------------
   sandbox/e_float/libs/e_float/test/real/cases/test_case_0000z_global_ops_pod.cpp | 67 ++++++++++++++++++++-----------------
   5 files changed, 56 insertions(+), 105 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-05 15:54:53 EDT (Fri, 05 Aug 2011)
@@ -58,8 +58,6 @@
     static const INT32 ef_digits10_extra = static_cast<INT32>(((static_cast<INT64>(ef_digits10) * 15LL) + 50LL) / 100LL);
     static const INT32 ef_digits10_tol = static_cast<INT32>(ef_digits10 + ((ef_digits10_extra < 15) ? 15 : ((ef_digits10_extra > 150) ? 150 : ef_digits10_extra)));
 
- static const std::string::size_type& width_of_exponent_field(void);
-
     virtual ~e_float_base() { }
 
     // Specific special values.

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-05 15:54:53 EDT (Fri, 05 Aug 2011)
@@ -72,20 +72,6 @@
   if(b_neg) { negate(); } return static_cast<e_float&>(*this);
 }
 
-const std::string::size_type& e_float_base::width_of_exponent_field(void)
-{
- static const std::string::size_type width_of_e_n64 =
- Util::lexical_cast((std::numeric_limits<INT64>::max)()).length();
-
- static const std::string::size_type width_of_e_long =
- Util::lexical_cast((std::numeric_limits<long>::max)()).length();
-
- static const std::string::size_type width_of_e =
- (std::max)(width_of_e_n64, width_of_e_long);
-
- return width_of_e;
-}
-
 void e_float_base::wr_string_scientific(std::string& str,
                                         const INT64 my_exp,
                                         const std::size_t os_precision,

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-05 15:54:53 EDT (Fri, 05 Aug 2011)
@@ -103,8 +103,7 @@
                                       fpclass (ef_finite),
                                       prec_elem(ef_elem_number)
 {
- (std::numeric_limits<char>::is_signed ? from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n))
- : from_unsigned_long(static_cast<unsigned long>(n)));
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
 }
 
 efx::e_float::e_float(const signed char n) : data (),
@@ -127,12 +126,11 @@
 
 efx::e_float::e_float(const wchar_t n) : data (),
                                          exp (static_cast<INT64>(0)),
- neg (std::numeric_limits<wchar_t>::is_signed ? (n < static_cast<wchar_t>(0)) : false),
+ neg (std::numeric_limits<wchar_t>::is_signed && (n < static_cast<wchar_t>(0))),
                                          fpclass (ef_finite),
                                          prec_elem(ef_elem_number)
 {
- (std::numeric_limits<wchar_t>::is_signed ? from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n))
- : from_unsigned_long(static_cast<unsigned long>(n)));
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
 }
 
 efx::e_float::e_float(const signed short n) : data (),

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-05 15:54:53 EDT (Fri, 05 Aug 2011)
@@ -54,53 +54,19 @@
   ::mpfr_init(rop);
 }
 
-mpfr::e_float::e_float(const char n)
-{
- const bool b_neg = (std::numeric_limits<char>::is_signed && (n < static_cast<char>(0)));
- from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
-
-mpfr::e_float::e_float(const signed char n)
-{
- const bool b_neg = (n < static_cast<signed char>(0));
- from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
-
-mpfr::e_float::e_float(const signed short n)
-{
- const bool b_neg = (n < static_cast<signed short>(0));
- from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
-
-mpfr::e_float::e_float(const signed int n)
-{
- const bool b_neg = (n < static_cast<signed int>(0));
- from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
-
-mpfr::e_float::e_float(const signed long n)
-{
- const bool b_neg = (n < static_cast<signed long>(0));
- from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
-
-mpfr::e_float::e_float(const signed long long n)
-{
- const bool b_neg = (n < static_cast<signed long long>(0));
- from_unsigned_long_long((!b_neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n));
- if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); }
-}
+mpfr::e_float::e_float(const char n) { const bool b_neg = (std::numeric_limits<char>::is_signed ? (n < static_cast<char> (0)) : false); from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+mpfr::e_float::e_float(const wchar_t n) { const bool b_neg = (std::numeric_limits<wchar_t>::is_signed ? (n < static_cast<wchar_t>(0)) : false); from_unsigned_long((!b_neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
 
-mpfr::e_float::e_float(const unsigned char n) { from_unsigned_long(static_cast<unsigned long>(n)); }
-mpfr::e_float::e_float(const wchar_t n) { from_unsigned_long(static_cast<unsigned long>(n)); }
-mpfr::e_float::e_float(const unsigned short n) { from_unsigned_long(static_cast<unsigned long>(n)); }
-mpfr::e_float::e_float(const unsigned int n) { from_unsigned_long(static_cast<unsigned long>(n)); }
-mpfr::e_float::e_float(const unsigned long n) { from_unsigned_long(static_cast<unsigned long>(n)); }
+mpfr::e_float::e_float(const signed char n) { const bool b_neg = (n < static_cast<signed char>(0)); from_unsigned_long ((!b_neg) ? static_cast<unsigned long> (n) : static_cast<unsigned long> (-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+mpfr::e_float::e_float(const signed short n) { const bool b_neg = (n < static_cast<signed short>(0)); from_unsigned_long ((!b_neg) ? static_cast<unsigned long> (n) : static_cast<unsigned long> (-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+mpfr::e_float::e_float(const signed int n) { const bool b_neg = (n < static_cast<signed int>(0)); from_unsigned_long ((!b_neg) ? static_cast<unsigned long> (n) : static_cast<unsigned long> (-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+mpfr::e_float::e_float(const signed long n) { const bool b_neg = (n < static_cast<signed long>(0)); from_unsigned_long ((!b_neg) ? static_cast<unsigned long> (n) : static_cast<unsigned long> (-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+mpfr::e_float::e_float(const signed long long n) { const bool b_neg = (n < static_cast<signed long long>(0)); from_unsigned_long_long((!b_neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n)); if(b_neg) { ::mpfr_neg(rop, rop, GMP_RNDN); } }
+
+mpfr::e_float::e_float(const unsigned char n) { from_unsigned_long (static_cast<unsigned long> (n)); }
+mpfr::e_float::e_float(const unsigned short n) { from_unsigned_long (static_cast<unsigned long> (n)); }
+mpfr::e_float::e_float(const unsigned int n) { from_unsigned_long (static_cast<unsigned long> (n)); }
+mpfr::e_float::e_float(const unsigned long n) { from_unsigned_long (static_cast<unsigned long> (n)); }
 mpfr::e_float::e_float(const unsigned long long n) { from_unsigned_long_long(static_cast<unsigned long long>(n)); }
 
 mpfr::e_float::e_float(const float f)
@@ -504,8 +470,8 @@
   const bool my_showpos = ((my_flags & std::ios::showpos) != 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(isnan()) { str = "NaN"; return; }
+ if(isinf()) { str = ((!isneg()) ? (my_showpos ? std::string("+INF") : std::string("INF")) : std::string("-INF")); return; }
 
 
   // Get the order-10 of the e_float. This is done using a partial string
@@ -606,11 +572,9 @@
     }
   }
 
- // Create a format string such as "%+.99RNe" for 100 digits
- // in scientific notation with lowercase and noshowpos.
- const std::size_t the_number_of_digits_scientific =
- ((the_number_of_digits_i_want_from_e_float > static_cast<std::size_t>(1u)) ? static_cast<std::size_t>(the_number_of_digits_i_want_from_e_float - 1u)
- : static_cast<std::size_t>(0u));
+ // Create a format string such as "%+.99RNe" in order to extract 100 digits
+ // in scientific notation with the lowercase and noshowpos flags.
+ const std::size_t the_number_of_digits_scientific = static_cast<std::size_t>((std::max)(the_number_of_digits_i_want_from_e_float, static_cast<std::size_t>(1u)) - static_cast<std::size_t>(1u));
   str_fmt = std::string("%.") + (Util::lexical_cast(the_number_of_digits_scientific) + "RNe");
 
   // Get the string representation of the e_float in scientific notation (lowercase, noshowpos).

Modified: sandbox/e_float/libs/e_float/test/real/cases/test_case_0000z_global_ops_pod.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/test/real/cases/test_case_0000z_global_ops_pod.cpp (original)
+++ sandbox/e_float/libs/e_float/test/real/cases/test_case_0000z_global_ops_pod.cpp 2011-08-05 15:54:53 EDT (Fri, 05 Aug 2011)
@@ -8,6 +8,10 @@
 // "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
 
+#if defined(_MSC_VER)
+#pragma warning(disable:4127)
+#endif
+
 #include <sstream>
 #include <string>
 #include <limits>
@@ -24,38 +28,39 @@
     static e_float the_value_min;
     static e_float the_value_max;
 
- template<typename STYPE>
- inline static bool check_stype(void)
+ template<typename T>
+ inline static bool check_type(void)
     {
- the_value_min = std::numeric_limits<STYPE>::min();
- the_value_max = std::numeric_limits<STYPE>::max();
+ the_value_min = std::numeric_limits<T>::min();
+ the_value_max = std::numeric_limits<T>::max();
 
       std::stringstream ss;
 
- ss << static_cast<signed long long>(std::numeric_limits<STYPE>::min());
+ if(std::numeric_limits<T>::is_signed)
+ {
+ ss << static_cast<signed long long>(std::numeric_limits<T>::min());
+ }
+ else
+ {
+ ss << static_cast<unsigned long long>(std::numeric_limits<T>::min());
+ }
       std::string str_min = ss.str();
 
       ss.clear();
       ss.str("");
 
- ss << static_cast<signed long long>(std::numeric_limits<STYPE>::max());
+ if(std::numeric_limits<T>::is_signed)
+ {
+ ss << static_cast<signed long long>(std::numeric_limits<T>::max());
+ }
+ else
+ {
+ ss << static_cast<unsigned long long>(std::numeric_limits<T>::max());
+ }
       std::string str_max = ss.str();
 
       return ((the_value_min == e_float(str_min)) && (the_value_max == e_float(str_max)));
     }
-
- template<typename UTYPE>
- inline static bool check_utype(void)
- {
- the_value_max = std::numeric_limits<UTYPE>::max();
-
- std::stringstream ss;
-
- ss << static_cast<unsigned long long>(std::numeric_limits<UTYPE>::max());
- std::string str_max = ss.str();
-
- return (the_value_max == e_float(str_max));
- }
   };
 
   e_float e_float_equate_to::the_value_min;
@@ -135,18 +140,18 @@
 
         my_test_result = true;
 
- my_test_result &= ::e_float_equate_to::check_utype<char>();
- my_test_result &= ::e_float_equate_to::check_stype<signed char>();
- my_test_result &= ::e_float_equate_to::check_utype<unsigned char>();
- my_test_result &= ::e_float_equate_to::check_utype<wchar_t>();
- my_test_result &= ::e_float_equate_to::check_stype<signed short>();
- my_test_result &= ::e_float_equate_to::check_utype<unsigned short>();
- my_test_result &= ::e_float_equate_to::check_stype<signed int>();
- my_test_result &= ::e_float_equate_to::check_utype<unsigned int>();
- my_test_result &= ::e_float_equate_to::check_stype<signed long>();
- my_test_result &= ::e_float_equate_to::check_utype<unsigned long>();
- my_test_result &= ::e_float_equate_to::check_stype<signed long long>();
- my_test_result &= ::e_float_equate_to::check_utype<unsigned long long>();
+ my_test_result &= ::e_float_equate_to::check_type<char>();
+ my_test_result &= ::e_float_equate_to::check_type<signed char>();
+ my_test_result &= ::e_float_equate_to::check_type<unsigned char>();
+ my_test_result &= ::e_float_equate_to::check_type<wchar_t>();
+ my_test_result &= ::e_float_equate_to::check_type<signed short>();
+ my_test_result &= ::e_float_equate_to::check_type<unsigned short>();
+ my_test_result &= ::e_float_equate_to::check_type<signed int>();
+ my_test_result &= ::e_float_equate_to::check_type<unsigned int>();
+ my_test_result &= ::e_float_equate_to::check_type<signed long>();
+ my_test_result &= ::e_float_equate_to::check_type<unsigned long>();
+ my_test_result &= ::e_float_equate_to::check_type<signed long long>();
+ my_test_result &= ::e_float_equate_to::check_type<unsigned long long>();
 
         e_float x(123u);
 


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