Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74217 - in sandbox/e_float/libs/e_float/src: e_float/efx e_float/gmp functions/elementary
From: e_float_at_[hidden]
Date: 2011-09-03 18:32:39


Author: christopher_kormanyos
Date: 2011-09-03 18:32:38 EDT (Sat, 03 Sep 2011)
New Revision: 74217
URL: http://svn.boost.org/trac/boost/changeset/74217

Log:
- Added some cosmetic changes to various source files.
Text files modified:
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 70 ++++++++++++++++++++-------------------
   sandbox/e_float/libs/e_float/src/e_float/gmp/e_float_gmp.cpp | 4 +-
   sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp | 27 +++++---------
   sandbox/e_float/libs/e_float/src/functions/elementary/elementary_trans.cpp | 44 +++++++++++++-----------
   4 files changed, 72 insertions(+), 73 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-09-03 18:32:38 EDT (Sat, 03 Sep 2011)
@@ -129,7 +129,7 @@
                                                   fpclass (ef_finite),
                                                   prec_elem(ef_elem_number)
 {
- from_unsigned_long_long((!neg) ? static_cast<unsigned long long>(n) : static_cast<UINT64>(-n));
+ from_unsigned_long_long((!neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n));
 }
 
 efx::e_float::e_float(const unsigned long long n) : data (),
@@ -286,7 +286,7 @@
   // Create an e_float from mantissa and exponent.
   // This ctor does not maintain the full precision of double.
 
- const bool mantissa_is_iszero = (::fabs(mantissa) < ((std::numeric_limits<double>::min)() * 2.0));
+ const bool mantissa_is_iszero = (::fabs(mantissa) < ((std::numeric_limits<double>::min)() * (1.0 + std::numeric_limits<double>::epsilon())));
 
   if(mantissa_is_iszero)
   {
@@ -296,8 +296,6 @@
 
   const bool b_neg = (mantissa < 0.0);
 
- neg = b_neg;
-
   double d = ((!b_neg) ? mantissa : -mantissa);
   INT64 e = exponent;
 
@@ -335,7 +333,7 @@
 
   exp = static_cast<INT64>(0);
 
- std::size_t i = 0u;
+ std::size_t i =static_cast<std::size_t>(0u);
 
   unsigned long uu = u;
 
@@ -363,7 +361,7 @@
 
   exp = static_cast<INT64>(0);
 
- std::size_t i = 0u;
+ std::size_t i =static_cast<std::size_t>(0u);
 
   unsigned long long uu = u;
 
@@ -413,8 +411,8 @@
   for(INT32 j = p - 1; j >= static_cast<INT32>(0); j--)
   {
     const UINT64 t = static_cast<UINT64>(carry + static_cast<UINT64>(u[j] * static_cast<UINT64>(n)));
- carry = static_cast<UINT64>(t / static_cast<UINT32>(e_float::ef_elem_mask));
- u[j] = static_cast<UINT32>(t - static_cast<UINT64>(static_cast<UINT32>(e_float::ef_elem_mask) * static_cast<UINT64>(carry)));
+ carry = static_cast<UINT64>(t / static_cast<UINT32>(ef_elem_mask));
+ u[j] = static_cast<UINT32>(t - static_cast<UINT64>(static_cast<UINT32>(ef_elem_mask) * static_cast<UINT64>(carry)));
   }
   
   return static_cast<UINT32>(carry);
@@ -426,7 +424,7 @@
 
   for(INT32 j = static_cast<INT32>(0); j < p; j++)
   {
- const UINT64 t = static_cast<UINT64>(u[j] + static_cast<UINT64>(prev * static_cast<UINT32>(e_float::ef_elem_mask)));
+ const UINT64 t = static_cast<UINT64>(u[j] + static_cast<UINT64>(prev * static_cast<UINT32>(ef_elem_mask)));
     u[j] = static_cast<UINT32>(t / n);
     prev = static_cast<UINT64>(t - static_cast<UINT64>(n * static_cast<UINT64>(u[j])));
   }
@@ -443,7 +441,7 @@
   else
   {
     const INT32 elems = static_cast<INT32>( static_cast<INT32>( (prec_digits + (ef_elem_digits10 / 2)) / ef_elem_digits10)
- + static_cast<INT32>(((prec_digits % ef_elem_digits10) != 0) ? 1 : 0));
+ + static_cast<INT32>(((prec_digits % ef_elem_digits10) != 0) ? 1 : 0));
 
     prec_elem = (std::min)(ef_elem_number, (std::max)(elems, static_cast<INT32>(2)));
   }
@@ -833,7 +831,7 @@
   {
     exp += static_cast<INT64>(ef_elem_digits10);
 
- // Shift result of the multiplication one element to the right.
+ // Shift the result of the multiplication one element to the right.
     std::copy_backward(data.begin(),
                        data.begin() + static_cast<std::size_t>(prec_elem - static_cast<INT32>(1)),
                        data.begin() + static_cast<std::size_t>(prec_elem));
@@ -1221,9 +1219,9 @@
     return true;
   }
 
- array_type::const_iterator it_first_non_zero = std::find_if(data.begin() + offset_decimal_part, data.end(), data_elem_is_non_zero_predicate);
+ array_type::const_iterator it_non_zero = std::find_if(data.begin() + offset_decimal_part, data.end(), data_elem_is_non_zero_predicate);
 
- return (it_first_non_zero == data.end());
+ return (it_non_zero == data.end());
 }
 
 efx::e_float& efx::e_float::operator++(void) { return *this += ef::one(); }
@@ -1252,11 +1250,9 @@
     ++exponent;
   }
 
- static const double d_mask = static_cast<double>(ef_elem_mask);
-
   mantissa = static_cast<double>(data[0])
- + (static_cast<double>(data[1]) / d_mask)
- + ((static_cast<double>(data[2]) / d_mask) / d_mask);
+ + (static_cast<double>(data[1]) / static_cast<double>(ef_elem_mask))
+ + ((static_cast<double>(data[2]) / static_cast<double>(ef_elem_mask)) / static_cast<double>(ef_elem_mask));
 
   mantissa /= static_cast<double>(p10);
 
@@ -1356,8 +1352,8 @@
 signed long long efx::e_float::extract_signed_long_long(void) const
 {
   // Extracts a signed long long from *this.
- // If |x| exceeds the maximum of signed long long,
- // then this maximum value is returned.
+ // If (x > maximum of signed long long) or (x < minimum of signed long long),
+ // then the maximum or minimum of signed long long is returned accordingly.
 
   if(exp < static_cast<INT64>(0))
   {
@@ -1366,36 +1362,42 @@
 
   const bool b_neg = isneg();
 
- const e_float xn = ef::fabs(extract_integer_part());
-
- signed long long val;
+ unsigned long long val;
 
- if(xn > ef::signed_long_long_max())
+ if((!b_neg) && (*this > ef::signed_long_long_max()))
   {
- val = (std::numeric_limits<signed long long>::max)();
+ return (std::numeric_limits<signed long long>::max)();
+ }
+ else if(b_neg && (*this < ef::signed_long_long_min()))
+ {
+ return (std::numeric_limits<signed long long>::min)();
   }
   else
   {
- // Extract the data into the int64 value.
- val = static_cast<signed long long>(xn.data[0]);
+ // Extract the data into an unsigned long long value.
+ const e_float xn(ef::fabs(extract_integer_part()));
+
+ val = static_cast<unsigned long long>(xn.data[0]);
 
     const INT32 imax = (std::min)(static_cast<INT32>(static_cast<INT32>(xn.exp) / ef_elem_digits10), static_cast<INT32>(ef_elem_number - static_cast<INT32>(1)));
 
     for(INT32 i = static_cast<INT32>(1); i <= imax; i++)
     {
- val *= static_cast<signed long long>(ef_elem_mask);
- val += static_cast<signed long long>(xn.data[i]);
+ val *= static_cast<unsigned long long>(ef_elem_mask);
+ val += static_cast<unsigned long long>(xn.data[i]);
     }
   }
 
- return ((!b_neg) ? val : static_cast<INT64>(-val));
+ return ((!b_neg) ? static_cast<signed long long>(val) : static_cast<signed long long>(-static_cast<signed long long>(val)));
 }
 
 unsigned long long efx::e_float::extract_unsigned_long_long(void) const
 {
   // Extracts an unsigned long long from *this.
- // If |x| exceeds the maximum of unsigned long long,
- // then this maximum value is returned.
+ // If x exceeds the maximum of unsigned long long,
+ // then the maximum of unsigned long long is returned.
+ // If x is negative, then the unsigned long long cast of
+ // the signed long long extracted value is returned.
 
   if(isneg())
   {
@@ -1407,17 +1409,17 @@
     return static_cast<unsigned long long>(0u);
   }
 
- const e_float xn = ef::fabs(extract_integer_part());
+ const e_float xn(extract_integer_part());
 
   unsigned long long val;
 
   if(xn > ef::unsigned_long_long_max())
   {
- val = (std::numeric_limits<unsigned long long>::max)();
+ return (std::numeric_limits<unsigned long long>::max)();
   }
   else
   {
- // Extract the data into the int64 value.
+ // Extract the data into an unsigned long long value.
     val = static_cast<unsigned long long>(xn.data[0]);
 
     const INT32 imax = (std::min)(static_cast<INT32>(static_cast<INT32>(xn.exp) / ef_elem_digits10), static_cast<INT32>(ef_elem_number - static_cast<INT32>(1)));

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-09-03 18:32:38 EDT (Sat, 03 Sep 2011)
@@ -182,7 +182,7 @@
 
   if(::_finite(f) == 0)
   {
- operator=(::_isnan(f) ? my_value_nan() : ((!b_neg) ? my_value_inf() : -my_value_inf()));
+ operator=((::_isnan(f) != 0) ? my_value_nan() : ((!b_neg) ? my_value_inf() : -my_value_inf()));
     return;
   }
 
@@ -678,7 +678,7 @@
   else
   {
     const int result = ::mpf_cmp(rop, v.rop);
-
+
     if (result > 0) { return static_cast<INT32>(1); }
     else if(result < 0) { return static_cast<INT32>(-1); }
     else { return static_cast<INT32>(0); }

Modified: sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp (original)
+++ sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp 2011-09-03 18:32:38 EDT (Sat, 03 Sep 2011)
@@ -75,7 +75,7 @@
 double ef::to_double(const ef_complex& z) { return ef::to_double(z.real()); }
 
 INT64 ef::to_int64(const double x) { return static_cast<INT64>(x); }
-INT64 ef::to_int64(const e_float& x) { return x.extract_signed_long_long(); }
+INT64 ef::to_int64(const e_float& x) { return static_cast<INT64>(x.extract_signed_long_long()); }
 INT64 ef::to_int64(const ef_complex& z) { return ef::to_int64(z.real()); }
 
 bool ef::isint(const double x)
@@ -100,28 +100,22 @@
 
 INT32 ef::to_int32(const double x)
 {
- static const INT64 n32_max = static_cast<INT64>((std::numeric_limits<INT32>::max)());
- static const INT64 n32_min = static_cast<INT64>((std::numeric_limits<INT32>::min)());
+ const INT64 n32_max = static_cast<INT64>((std::numeric_limits<INT32>::max)());
+ const INT64 n32_min = static_cast<INT64>((std::numeric_limits<INT32>::min)());
 
- INT64 n64 = ef::to_int64(x);
+ const INT64 n64 = ef::to_int64(x);
 
- if(n64 < n32_min) { n64 = n32_min; }
- if(n64 > n32_max) { n64 = n32_max; }
-
- return static_cast<INT32>(n64);
+ return static_cast<INT32>((std::min)((std::max)(n64, n32_min), n32_max));
 }
 
 INT32 ef::to_int32(const e_float& x)
 {
- static const INT64 n32_max = static_cast<INT64>((std::numeric_limits<INT32>::max)());
- static const INT64 n32_min = static_cast<INT64>((std::numeric_limits<INT32>::min)());
-
- INT64 n64 = ef::to_int64(x);
+ const INT64 n32_max = static_cast<INT64>((std::numeric_limits<INT32>::max)());
+ const INT64 n32_min = static_cast<INT64>((std::numeric_limits<INT32>::min)());
 
- if(n64 < n32_min) { n64 = n32_min; }
- if(n64 > n32_max) { n64 = n32_max; }
+ const INT64 n64 = ef::to_int64(x);
 
- return static_cast<INT32>(n64);
+ return static_cast<INT32>((std::min)((std::max)(n64, n32_min), n32_max));
 }
 
 INT32 ef::to_int32(const ef_complex& z)
@@ -177,8 +171,7 @@
 bool ef::large_arg(const e_float& x)
 {
   static const double lim_d = static_cast<double>(static_cast<INT32>(ef::tol())) / 10.0;
- static const INT64 lim_n = static_cast<INT64>(lim_d);
- static const INT64 lim = (lim_n < 6 ? 6 : lim_n);
+ static const INT64 lim = (std::max)(static_cast<INT64>(lim_d), static_cast<INT64>(6));
 
   return (x.order() > lim);
 }

Modified: sandbox/e_float/libs/e_float/src/functions/elementary/elementary_trans.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/functions/elementary/elementary_trans.cpp (original)
+++ sandbox/e_float/libs/e_float/src/functions/elementary/elementary_trans.cpp 2011-09-03 18:32:38 EDT (Sat, 03 Sep 2011)
@@ -417,26 +417,26 @@
 
   if(ef::isinf(x))
   {
- return (!ef::isneg(x) ? std::numeric_limits<e_float>::infinity() : ef::zero());
+ return ((!ef::isneg(x)) ? std::numeric_limits<e_float>::infinity() : ef::zero());
   }
 
- if(ef::iszero(x) || x.order() < -ef::tol())
+ if(ef::iszero(x) || (x.order() < -ef::tol()))
   {
     return ef::one();
   }
 
   // Get local copy of argument and force it to be positive.
   const bool bo_x_is_neg = ef::isneg(x);
-
- const e_float xx = !bo_x_is_neg ? x : -x;
+
+ const e_float xx = ((!bo_x_is_neg) ? x : -x);
 
   // Check the range of the argument.
- static const e_float maximum_arg_for_exp = e_float(std::numeric_limits<e_float>::max_exponent);
+ static const e_float maximum_arg_for_exp = std::numeric_limits<e_float>::max_exponent;
 
   if(xx > maximum_arg_for_exp)
   {
     // Overflow / underflow
- return !bo_x_is_neg ? std::numeric_limits<e_float>::infinity() : ef::zero();
+ return ((!bo_x_is_neg) ? std::numeric_limits<e_float>::infinity() : ef::zero());
   }
 
   // Check for pure-integer arguments which can be either signed or unsigned.
@@ -447,31 +447,35 @@
 
   // The algorithm for exp has been taken from MPFUN.
   // exp(t) = [ (1 + r + r^2/2! + r^3/3! + r^4/4! ...)^p2 ] * 2^n
- // where p2 is a power of 2 such as 512, r = t_prime / p2, and
+ // where p2 is a power of 2 such as 2048, r = t_prime / p2, and
   // t_prime = t - n*ln2, with n chosen to minimize the absolute
   // value of t_prime. In the resulting Taylor series, which is
   // implemented as a hypergeometric function, |r| is bounded by
   // ln2 / p2. For small arguments, no scaling is done.
 
- static const e_float one_over_ln2 = ef::one() / ef::ln2();
-
- e_float nf = ef::integer_part(xx * one_over_ln2);
-
- // Scaling.
- static const INT32 p2 = static_cast<INT32>(UINT32(1u) << 11);
-
- const bool b_scale = xx.order() > static_cast<INT64>(-4);
+ const bool b_scale = (xx.order() > static_cast<INT64>(-4));
 
   // Compute the exponential series of the (possibly) scaled argument.
- e_float exp_series = ef::hyp0F0(b_scale ? (xx - nf * ef::ln2()) / p2 : xx);
+ e_float exp_series;
 
   if(b_scale)
   {
- exp_series = ef::pown(exp_series, p2);
- exp_series *= ef::pow2(ef::to_int64(nf));
+ // Compute 1 / ln2 as a warm-cached constant value.
+ static const e_float one_over_ln2 = ef::one() / ef::ln2();
+
+ const e_float nf = ef::integer_part(xx * one_over_ln2);
+
+ // The scaling is 2^11 = 2048.
+ const INT32 p2 = static_cast<INT32>(UINT32(1u) << 11);
+
+ exp_series = ef::pown(ef::hyp0F0((xx - (nf * ef::ln2())) / p2), static_cast<INT64>(p2)) * ef::pow2(ef::to_int64(nf));
   }
-
- return ((!bo_x_is_neg) ? exp_series : exp_series.calculate_inv());
+ else
+ {
+ exp_series = ef::hyp0F0(xx);
+ }
+
+ return ((!bo_x_is_neg) ? exp_series : (ef::one() / exp_series));
 }
 
 namespace Log_Series


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