Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73595 - in sandbox/e_float: boost/e_float libs/e_float/src/e_float/efx libs/e_float/src/e_float/mpfr
From: e_float_at_[hidden]
Date: 2011-08-07 09:47:56


Author: christopher_kormanyos
Date: 2011-08-07 09:47:55 EDT (Sun, 07 Aug 2011)
New Revision: 73595
URL: http://svn.boost.org/trac/boost/changeset/73595

Log:
- Brought MPFR back-end into conformity.
Text files modified:
   sandbox/e_float/boost/e_float/e_float_base.hpp | 19 +++--
   sandbox/e_float/boost/e_float/e_float_efx.hpp | 2
   sandbox/e_float/boost/e_float/e_float_gmp.hpp | 12 ++-
   sandbox/e_float/boost/e_float/e_float_mpfr.hpp | 12 ++-
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 2
   sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr.cpp | 133 +++++++++++++++++++++++++++++++++------
   sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr_protos.h | 1
   7 files changed, 138 insertions(+), 43 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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -91,7 +91,7 @@
     virtual e_float_base& calculate_inv (void) = 0;
     virtual e_float_base& calculate_sqrt(void) = 0;
 
- // Comparison functions
+ // Comparison functions.
     virtual bool isnan (void) const = 0;
     virtual bool isinf (void) const = 0;
     virtual bool isfinite(void) const = 0;
@@ -104,15 +104,15 @@
 
     virtual e_float_base& negate(void) = 0;
 
- // Operators pre-increment and pre-decrement
+ // Operators pre-increment and pre-decrement.
     virtual e_float_base& operator++(void) = 0;
     virtual e_float_base& operator--(void) = 0;
 
- // Argument range and check functions
+ // Fast order-10 range and check.
     INT64 order(void) const { return get_order_approximate(); }
 
- // Conversion routines
- virtual void extract_parts(double&, INT64&) const = 0;
+ // Conversion routines.
+ virtual void extract_parts (double&, INT64&) const = 0;
     virtual double extract_double (void) const = 0;
     virtual long double extract_long_double (void) const = 0;
     virtual signed long long extract_signed_long_long (void) const = 0;
@@ -124,8 +124,8 @@
     void wr_string(std::string& str, std::ostream& os) const;
     virtual bool rd_string(const char* const) = 0;
 
- // Cast operators
- operator char() const { return (std::numeric_limits<char>::is_signed ? static_cast<char>(extract_signed_long_long()) : static_cast<char>(extract_unsigned_long_long())); }
+ // Cast operators with all built-in types.
+ operator char() const { return (std::numeric_limits<char>::is_signed ? static_cast<char>(extract_signed_long_long()) : static_cast<char>(extract_unsigned_long_long())); }
     operator wchar_t() const { return (std::numeric_limits<char>::is_signed ? static_cast<wchar_t>(extract_signed_long_long()) : static_cast<wchar_t>(extract_unsigned_long_long())); }
     operator signed char() const { return static_cast<signed char> (extract_signed_long_long()); }
     operator signed short() const { return static_cast<signed short> (extract_signed_long_long()); }
@@ -208,16 +208,17 @@
       const int& get_exponent(void) const { return e; }
 
     private:
+ native_float_parts();
       native_float_parts(const native_float_parts&);
       const native_float_parts& operator=(const native_float_parts&);
 
       unsigned long long u;
       int e;
 
- native_float_parts();
-
       void make_parts(const native_float_type f)
       {
+ if(f == static_cast<native_float_type>(0.0)) { return; }
+
         // Get the fraction and base-2 exponent.
         native_float_type man = ::frexp(f, &e);
 

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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -135,7 +135,7 @@
       virtual e_float& operator--(void);
 
       // Conversion routines
- virtual void extract_parts (double& mantissa, INT64& exponent) const;
+ virtual void extract_parts (double& mantissa, INT64& exponent) const;
       virtual double extract_double (void) const;
       virtual long double extract_long_double (void) const;
       virtual signed long long extract_signed_long_long (void) const;

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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -152,11 +152,13 @@
       virtual e_float& operator--(void);
 
       // Conversion routines
- virtual void extract_parts (double& mantissa, INT64& exponent) const;
- virtual double extract_double (void) const;
- virtual INT64 extract_signed_long_long (void) const;
- virtual e_float extract_integer_part(void) const;
- virtual e_float extract_decimal_part(void) const;
+ virtual void extract_parts (double& mantissa, INT64& exponent) const;
+ virtual double extract_double (void) const;
+ virtual long double extract_long_double (void) const;
+ virtual signed long long extract_signed_long_long (void) const;
+ virtual unsigned long long extract_unsigned_long_long(void) const;
+ virtual e_float extract_integer_part (void) const;
+ virtual e_float extract_decimal_part (void) const;
 
     private:
       static const INT64& max_exp2(void);

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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -138,11 +138,13 @@
       virtual e_float& operator++(void);
       virtual e_float& operator--(void);
 
- virtual void extract_parts (double& mantissa, INT64& exponent) const;
- virtual double extract_double (void) const;
- virtual INT64 extract_signed_long_long (void) const;
- virtual e_float extract_integer_part(void) const;
- virtual e_float extract_decimal_part(void) const;
+ virtual void extract_parts (double& mantissa, INT64& exponent) const;
+ virtual double extract_double (void) const;
+ virtual long double extract_long_double (void) const;
+ virtual signed long long extract_signed_long_long (void) const;
+ virtual unsigned long long extract_unsigned_long_long(void) const;
+ virtual e_float extract_integer_part (void) const;
+ virtual e_float extract_decimal_part (void) const;
 
       static e_float my_cbrt (const e_float& x);
       static e_float my_rootn (const e_float& x, const UINT32 p);

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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -1364,7 +1364,7 @@
   // Check for zero e_float.
   if(iszero() || (xx < ef::long_double_min()))
   {
- return 0.0;
+ return static_cast<long double>(0.0);
   }
 
   // Check if e_float exceeds the maximum of double.

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-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -326,20 +326,33 @@
 {
   const bool b_neg = isneg();
 
- const e_float xx = ef::fabs(*this);
+ // Check for non-normal e_float.
+ if(!isfinite())
+ {
+ if(isnan())
+ {
+ return std::numeric_limits<double>::quiet_NaN();
+ }
+ else
+ {
+ return ((!b_neg) ? std::numeric_limits<double>::infinity()
+ : -std::numeric_limits<double>::infinity());
+ }
+ }
 
- static const e_float dbl_max((std::numeric_limits<double>::max)());
- static const e_float dbl_min((std::numeric_limits<double>::min)());
+ const e_float xx(ef::fabs(*this));
 
- if(xx > dbl_max)
+ // Check for zero e_float.
+ if(iszero() || (xx < ef::double_min()))
   {
- return ((!b_neg) ? (std::numeric_limits<double>::max)()
- : -(std::numeric_limits<double>::max)());
+ return 0.0;
   }
- else if(xx < dbl_min)
+
+ // Check if e_float exceeds the maximum of double.
+ if(xx > ef::double_max())
   {
- return ((!b_neg) ? (std::numeric_limits<double>::min)()
- : -(std::numeric_limits<double>::min)());
+ return ((!b_neg) ? std::numeric_limits<double>::infinity()
+ : -std::numeric_limits<double>::infinity());
   }
 
   const double dx = ::mpfr_get_d(xx.rop, GMP_RNDN);
@@ -347,48 +360,124 @@
   return ((!b_neg) ? dx : -dx);
 }
 
-INT64 mpfr::e_float::extract_signed_long_long(void) const
+long double mpfr::e_float::extract_long_double(void) const
 {
   const bool b_neg = isneg();
 
- const e_float nx = ef::fabs(*this);
+ // Check for non-normal e_float.
+ if(!isfinite())
+ {
+ if(isnan())
+ {
+ return std::numeric_limits<long double>::quiet_NaN();
+ }
+ else
+ {
+ return ((!b_neg) ? std::numeric_limits<long double>::infinity()
+ : -std::numeric_limits<long double>::infinity());
+ }
+ }
+
+ const e_float xx(ef::fabs(*this));
 
- static const e_float n64_max((std::numeric_limits<INT64>::max)());
+ // Check for zero e_float.
+ if(iszero() || (xx < ef::long_double_min()))
+ {
+ return static_cast<long double>(0.0);
+ }
 
- if(nx > n64_max)
+ // Check if e_float exceeds the maximum of double.
+ if(xx > ef::long_double_max())
   {
- return ((!b_neg) ? (std::numeric_limits<INT64>::max)()
- : -(std::numeric_limits<INT64>::max)());
+ return ((!b_neg) ? std::numeric_limits<long double>::infinity()
+ : -std::numeric_limits<long double>::infinity());
+ }
+
+ const long double ldx = ::mpfr_get_ld(xx.rop, GMP_RNDN);
+
+ return ((!b_neg) ? ldx : -ldx);
+}
+
+signed long long mpfr::e_float::extract_signed_long_long(void) const
+{
+ const bool b_neg = isneg();
+
+ const e_float nx = ef::fabs(*this);
+
+ if(nx > ef::signed_long_long_max())
+ {
+ return ((!b_neg) ? (std::numeric_limits<signed long long>::max)()
+ : -(std::numeric_limits<signed long long>::max)());
   }
   
   if(nx < ef::one())
   {
- return static_cast<INT64>(0);
+ return static_cast<signed long long>(0);
   }
 
   if(nx.isone())
   {
- return static_cast<INT64>(!b_neg ? static_cast<INT64>(1) : static_cast<INT64>(-1));
+ return ((!b_neg) ? static_cast<signed long long>(1) : static_cast<signed long long>(-1));
   }
 
- std::tr1::array<char, 32u> str = {{ static_cast<char>('0') }};
+ std::tr1::array<char, 64u> str = {{ static_cast<char>('0') }};
 
   mp_exp_t p10;
 
   static_cast<void>(::mpfr_get_str(str.data(), &p10, 10, str.size() - 1u, nx.rop, GMP_RNDN));
 
- std::string str_n64(static_cast<std::size_t>(p10), static_cast<char>('0'));
+ std::string str_sll(static_cast<std::size_t>(p10), static_cast<char>('0'));
 
- std::copy(str.begin(), str.begin() + str_n64.size(), str_n64.begin());
+ std::copy(str.begin(), str.begin() + str_sll.size(), str_sll.begin());
 
   std::stringstream ss;
- ss << str_n64;
- INT64 n;
+ ss << str_sll;
+ signed long long n;
   ss >> n;
 
   return ((!b_neg) ? n : -n);
 }
 
+unsigned long long mpfr::e_float::extract_unsigned_long_long(void) const
+{
+ if(isneg())
+ {
+ return static_cast<unsigned long long>(extract_signed_long_long());
+ }
+
+ if(*this > ef::unsigned_long_long_max())
+ {
+ return (std::numeric_limits<unsigned long long>::max)();
+ }
+
+ if(*this < ef::one())
+ {
+ return static_cast<unsigned long long>(0u);
+ }
+
+ if(isone())
+ {
+ return static_cast<unsigned long long>(1u);
+ }
+
+ std::tr1::array<char, 64u> str = {{ static_cast<char>('0') }};
+
+ mp_exp_t p10;
+
+ static_cast<void>(::mpfr_get_str(str.data(), &p10, 10, str.size() - 1u, rop, GMP_RNDN));
+
+ std::string str_ull(static_cast<std::size_t>(p10), static_cast<char>('0'));
+
+ std::copy(str.begin(), str.begin() + str_ull.size(), str_ull.begin());
+
+ std::stringstream ss;
+ ss << str_ull;
+ unsigned long long n;
+ ss >> n;
+
+ return n;
+}
+
 mpfr::e_float mpfr::e_float::extract_integer_part(void) const
 {
   const bool b_neg = isneg();

Modified: sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr_protos.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr_protos.h (original)
+++ sandbox/e_float/libs/e_float/src/e_float/mpfr/e_float_mpfr_protos.h 2011-08-07 09:47:55 EDT (Sun, 07 Aug 2011)
@@ -60,6 +60,7 @@
     int mpfr_sprintf(char*, const char*, ...);
 
     double mpfr_get_d (mpfr_srcptr, mp_rnd_t);
+ long double mpfr_get_ld (mpfr_srcptr, mp_rnd_t);
     unsigned long mpfr_get_si (mpfr_srcptr, mp_rnd_t);
     double mpfr_get_d_2exp(signed long int*, mpfr_srcptr, mp_rnd_t);
     char* mpfr_get_str (char*, mp_exp_t*, int, size_t, mpfr_srcptr, mp_rnd_t);


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