Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75072 - in sandbox/multiprecision: boost/multiprecision/utility libs/multiprecision/src/backends/float/efx libs/multiprecision/src/functions/elementary libs/multiprecision/test/real/cases
From: e_float_at_[hidden]
Date: 2011-10-20 15:49:23


Author: christopher_kormanyos
Date: 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
New Revision: 75072
URL: http://svn.boost.org/trac/boost/changeset/75072

Log:
- Trapezoid rule utility cleaned up.
- Spaces in editing cleaned up after previous text substitutions.
- Error in sign of asin for small argument corrected. Test cases added.
- Slowdown in pow function eliminated.
Text files modified:
   sandbox/multiprecision/boost/multiprecision/utility/util_trapezoid.hpp | 24 ++++++---------
   sandbox/multiprecision/libs/multiprecision/src/backends/float/efx/mp_float_efx.cpp | 62 ++++++++++++++++++++--------------------
   sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trans.cpp | 12 +++----
   sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trig.cpp | 33 ++++++++++----------
   sandbox/multiprecision/libs/multiprecision/test/real/cases/test_case_00114_various_trig.cpp | 6 +++
   5 files changed, 67 insertions(+), 70 deletions(-)

Modified: sandbox/multiprecision/boost/multiprecision/utility/util_trapezoid.hpp
==============================================================================
--- sandbox/multiprecision/boost/multiprecision/utility/util_trapezoid.hpp (original)
+++ sandbox/multiprecision/boost/multiprecision/utility/util_trapezoid.hpp 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
@@ -11,9 +11,8 @@
 #ifndef _UTIL_TRAPEZOID_2008_09_06_HPP_
   #define _UTIL_TRAPEZOID_2008_09_06_HPP_
 
- //#include "util_ranged_function_operation.hpp"
-
-#include <boost/multiprecision/utility/util_ranged_function_operation.hpp>
+ #include <boost/cstdint.hpp>
+ #include "util_ranged_function_operation.hpp"
 
   namespace boost
   {
@@ -21,21 +20,19 @@
     {
       namespace utility
       {
- template<typename T> class recursive_trapezoid_rule : public ranged_function_operation<T>
+ template<typename T>
+ class recursive_trapezoid_rule : public ranged_function_operation<T>
         {
- protected:
-
- recursive_trapezoid_rule(const T& lo, const T& hi, const T& tol) : ranged_function_operation<T>(lo, hi, tol) { }
-
         public:
-
           virtual ~recursive_trapezoid_rule() { }
 
- private:
+ protected:
+ recursive_trapezoid_rule(const T& lo, const T& hi, const T& tol) : ranged_function_operation<T>(lo, hi, tol) { }
 
+ private:
           virtual T my_operation(void) const
           {
- boost::int32_t n = static_cast<boost::int32_t>(1);
+ boost::int_fast32_t n = static_cast<boost::int_fast32_t>(1);
 
             T a = ranged_function_operation<T>::xlo;
             T b = ranged_function_operation<T>::xhi;
@@ -54,9 +51,8 @@
 
               T sum(0);
 
- for(boost::int32_t j = static_cast<boost::int32_t>(1); j <= n; j++)
+ for(boost::int_fast32_t j = static_cast<boost::int_fast32_t>(1); j <= n; j++)
               {
- //sum += function_base<T>::function(a + (T((j * 2) - 1) * h));
                 sum += function(a + (T((j * 2) - 1) * h));
               }
 
@@ -71,7 +67,7 @@
                 break;
               }
 
- n = n * 2;
+ n = n * static_cast<boost::int_fast32_t>(2);
             }
 
             return I;

Modified: sandbox/multiprecision/libs/multiprecision/src/backends/float/efx/mp_float_efx.cpp
==============================================================================
--- sandbox/multiprecision/libs/multiprecision/src/backends/float/efx/mp_float_efx.cpp (original)
+++ sandbox/multiprecision/libs/multiprecision/src/backends/float/efx/mp_float_efx.cpp 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
@@ -123,10 +123,10 @@
 }
 
 mp_float_efx::mp_float_efx(const signed long long n) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (n < static_cast<signed long long>(0)),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ exp (static_cast<boost::int64_t>(0)),
+ neg (n < static_cast<signed long long>(0)),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   from_unsigned_long_long((!neg) ? static_cast<unsigned long long>(n) : static_cast<unsigned long long>(-n));
 }
@@ -176,10 +176,10 @@
 }
 
 mp_float_efx::mp_float_efx(const double d) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (false),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ exp (static_cast<boost::int64_t>(0)),
+ neg (false),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   const bool b_neg = (d < 0.0);
 
@@ -211,10 +211,10 @@
 }
 
 mp_float_efx::mp_float_efx(const long double ld) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (false),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ exp (static_cast<boost::int64_t>(0)),
+ neg (false),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   const bool b_neg = (ld < static_cast<long double>(0.0));
 
@@ -246,10 +246,10 @@
 }
 
 mp_float_efx::mp_float_efx(const char* const s) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (false),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ exp (static_cast<boost::int64_t>(0)),
+ neg (false),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   if(!rd_string(s))
   {
@@ -261,10 +261,10 @@
 }
 
 mp_float_efx::mp_float_efx(const std::string& str) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (false),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ exp (static_cast<boost::int64_t>(0)),
+ neg (false),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   if(!rd_string(str.c_str()))
   {
@@ -276,11 +276,11 @@
 }
 
 mp_float_efx::mp_float_efx(const double mantissa,
- const boost::int64_t exponent) : data (),
- exp (static_cast<boost::int64_t>(0)),
- neg (false),
- fpclass (mp_finite),
- prec_elem(mp_elem_number)
+ const boost::int64_t exponent) : data (),
+ exp (static_cast<boost::int64_t>(0)),
+ neg (false),
+ fpclass (mp_finite),
+ prec_elem(mp_elem_number)
 {
   // Create an mp_float_efx from mantissa and exponent.
   // This ctor does not maintain the full precision of double.
@@ -410,8 +410,8 @@
   for(boost::int32_t j = p - 1; j >= static_cast<boost::int32_t>(0); j--)
   {
     const boost::uint64_t t = static_cast<boost::uint64_t>(carry + static_cast<boost::uint64_t>(u[j] * static_cast<boost::uint64_t>(n)));
- carry = static_cast<boost::uint64_t>(t / static_cast<boost::uint32_t>(mp_elem_mask));
- u[j] = static_cast<boost::uint32_t>(t - static_cast<boost::uint64_t>(static_cast<boost::uint32_t>(mp_elem_mask) * static_cast<boost::uint64_t>(carry)));
+ carry = static_cast<boost::uint64_t>(t / static_cast<boost::uint32_t>(mp_elem_mask));
+ u[j] = static_cast<boost::uint32_t>(t - static_cast<boost::uint64_t>(static_cast<boost::uint32_t>(mp_elem_mask) * static_cast<boost::uint64_t>(carry)));
   }
   
   return static_cast<boost::uint32_t>(carry);
@@ -424,8 +424,8 @@
   for(boost::int32_t j = static_cast<boost::int32_t>(0); j < p; j++)
   {
     const boost::uint64_t t = static_cast<boost::uint64_t>(u[j] + static_cast<boost::uint64_t>(prev * static_cast<boost::uint32_t>(mp_elem_mask)));
- u[j] = static_cast<boost::uint32_t>(t / n);
- prev = static_cast<boost::uint64_t>(t - static_cast<boost::uint64_t>(n * static_cast<boost::uint64_t>(u[j])));
+ u[j] = static_cast<boost::uint32_t>(t / n);
+ prev = static_cast<boost::uint64_t>(t - static_cast<boost::uint64_t>(n * static_cast<boost::uint64_t>(u[j])));
   }
 
   return static_cast<boost::uint32_t>(prev);
@@ -440,7 +440,7 @@
   else
   {
     const boost::int32_t elems = static_cast<boost::int32_t>( static_cast<boost::int32_t>( (prec_digits + (mp_elem_digits10 / 2)) / mp_elem_digits10)
- + static_cast<boost::int32_t>(((prec_digits % mp_elem_digits10) != 0) ? 1 : 0));
+ + static_cast<boost::int32_t>(((prec_digits % mp_elem_digits10) != 0) ? 1 : 0));
 
     prec_elem = (std::min)(mp_elem_number, (std::max)(elems, static_cast<boost::int32_t>(2)));
   }
@@ -501,7 +501,7 @@
   array_type::iterator p_u = data.begin();
   array_type::const_iterator p_v = v.data.begin();
   bool b_copy = false;
- const boost::int32_t ofs = static_cast<boost::int32_t>(static_cast<boost::int32_t>(ofs_exp) / mp_elem_digits10);
+ const boost::int32_t ofs = static_cast<boost::int32_t>(static_cast<boost::int32_t>(ofs_exp) / mp_elem_digits10);
   array_type n_data;
 
   if(neg == v.neg)

Modified: sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trans.cpp
==============================================================================
--- sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trans.cpp (original)
+++ sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trans.cpp 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
@@ -676,18 +676,16 @@
     return boost::multiprecision::one() / boost::multiprecision::pow(x, -a);
   }
 
- const mp_float a_int = boost::multiprecision::integer_part(a);
- const boost::int64_t an = boost::multiprecision::to_int64(a_int);
- const mp_float da = a - a_int;
+ const mp_float a_int = boost::multiprecision::integer_part(a);
+ const boost::int64_t an = boost::multiprecision::to_int64(a_int);
+ const mp_float da = a - a_int;
 
   if(bo_a_isint)
   {
     return boost::multiprecision::pown(x, an);
   }
 
- static const mp_float nine_tenths = boost::multiprecision::nine() / static_cast<boost::int32_t>(10);
-
- if(boost::multiprecision::ispos(x) && (x > boost::multiprecision::tenth()) && (x < nine_tenths))
+ if(boost::multiprecision::ispos(x) && (x > boost::multiprecision::tenth()) && (x < boost::multiprecision::half()))
   {
     if(boost::multiprecision::small_arg(a))
     {
@@ -699,7 +697,7 @@
       // Series expansion for moderately sized x. Note that for large power of a,
       // the power of the integer part of a is calculated using the pown function.
       return ((an != static_cast<boost::int64_t>(0)) ? boost::multiprecision::hyp1F0(-da, boost::multiprecision::one() - x) * boost::multiprecision::pown(x, an)
- : boost::multiprecision::hyp1F0( -a, boost::multiprecision::one() - x));
+ : boost::multiprecision::hyp1F0( -a, boost::multiprecision::one() - x));
     }
   }
   else

Modified: sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trig.cpp
==============================================================================
--- sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trig.cpp (original)
+++ sandbox/multiprecision/libs/multiprecision/src/functions/elementary/elementary_trig.cpp 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
@@ -185,7 +185,7 @@
 
   // Check if the reduced argument is very close to 0 or pi/2.
   const bool b_near_zero = boost::multiprecision::small_arg(xx);
- const mp_float delta_pi_half = boost::multiprecision::pi_half() - xx;
+ const mp_float delta_pi_half = boost::multiprecision::pi_half() - xx;
   const bool b_near_pi_half = boost::multiprecision::small_arg(delta_pi_half);
   
   mp_float cos_val;
@@ -290,7 +290,7 @@
   {
     return boost::multiprecision::zero();
   }
-
+
   if(boost::multiprecision::isone(xx))
   {
     return ((!b_neg) ? boost::multiprecision::pi_half() : -boost::multiprecision::pi_half());
@@ -299,23 +299,21 @@
   if(boost::multiprecision::small_arg(xx))
   {
     // http://functions.wolfram.com/ElementaryFunctions/ArcSin/26/01/01/
- const mp_float asin_value = x * boost::multiprecision::hyp2F1(boost::multiprecision::half(),
- boost::multiprecision::half(),
- boost::multiprecision::three_half(),
- (x * x));
-
- return !b_neg ? asin_value : -asin_value;
+ return x * boost::multiprecision::hyp2F1(boost::multiprecision::half(),
+ boost::multiprecision::half(),
+ boost::multiprecision::three_half(),
+ (x * x));
   }
   else if(boost::multiprecision::near_one(xx))
   {
     const mp_float dx1 = boost::multiprecision::one() - xx;
 
- const mp_float asin_value = boost::multiprecision::pi_half()
+ const mp_float asin_value = boost::multiprecision::pi_half()
                                - ( boost::multiprecision::sqrt(dx1 * static_cast<boost::int32_t>(2))
                                   * boost::multiprecision::hyp2F1(boost::multiprecision::half(),
- boost::multiprecision::half(),
- boost::multiprecision::three_half(),
- dx1 / static_cast<boost::int32_t>(2)));
+ boost::multiprecision::half(),
+ boost::multiprecision::three_half(),
+ dx1 / static_cast<boost::int32_t>(2)));
 
     return ((!b_neg) ? asin_value : -asin_value);
   }
@@ -329,7 +327,7 @@
   static const boost::int64_t p10_max = static_cast<boost::int64_t>(std::numeric_limits<double>::max_exponent10);
 
   const double de = static_cast<double>(ne < static_cast<boost::int64_t>(0) ? static_cast<boost::int32_t>((std::max)(ne, p10_min))
- : static_cast<boost::int32_t>((std::min)(ne, p10_max)));
+ : static_cast<boost::int32_t>((std::min)(ne, p10_max)));
 
   mp_float value = mp_float(::asin(dd * ::pow(10.0, de)));
 
@@ -361,7 +359,8 @@
 
   if(boost::multiprecision::fabs(x) > boost::multiprecision::one()) { return std::numeric_limits<mp_float>::quiet_NaN(); }
 
- return boost::multiprecision::iszero(x) ? boost::multiprecision::pi_half() : boost::multiprecision::pi_half() - boost::multiprecision::asin(x);
+ return (boost::multiprecision::iszero(x) ? boost::multiprecision::pi_half()
+ : (boost::multiprecision::pi_half() - boost::multiprecision::asin(x)));
 }
 
 namespace
@@ -401,7 +400,7 @@
 
   if(x.isinf() || order > boost::multiprecision::tol())
   {
- return boost::multiprecision::ispos(x) ? boost::multiprecision::pi_half() : -boost::multiprecision::pi_half();
+ return (boost::multiprecision::ispos(x) ? boost::multiprecision::pi_half() : -boost::multiprecision::pi_half());
   }
   else if(boost::multiprecision::iszero(x))
   {
@@ -432,7 +431,7 @@
   static const boost::int64_t p10_max = static_cast<boost::int64_t>(std::numeric_limits<double>::max_exponent10);
 
   const double de = static_cast<double>(ne < static_cast<boost::int64_t>(0) ? static_cast<boost::int32_t>((std::max)(ne, p10_min))
- : static_cast<boost::int32_t>((std::min)(ne, p10_max)));
+ : static_cast<boost::int32_t>((std::min)(ne, p10_max)));
 
   mp_float value = order < static_cast<boost::int64_t>(2) ? mp_float(::atan(dd * ::pow(10.0, de)))
                                                           : ::my_atan_series_at_infinity(xx);
@@ -452,7 +451,7 @@
 
 mp_float boost::multiprecision::atan2(const mp_float& y, const mp_float& x)
 {
- if(!boost::multiprecision::isfinite(x) || !boost::multiprecision::isfinite(y))
+ if((!boost::multiprecision::isfinite(x)) || (!boost::multiprecision::isfinite(y)))
   {
     return x;
   }

Modified: sandbox/multiprecision/libs/multiprecision/test/real/cases/test_case_00114_various_trig.cpp
==============================================================================
--- sandbox/multiprecision/libs/multiprecision/test/real/cases/test_case_00114_various_trig.cpp (original)
+++ sandbox/multiprecision/libs/multiprecision/test/real/cases/test_case_00114_various_trig.cpp 2011-10-20 15:49:21 EDT (Thu, 20 Oct 2011)
@@ -35,13 +35,17 @@
         data.clear();
         data.push_back(boost::multiprecision::sec(boost::multiprecision::euler_gamma()));
         data.push_back(boost::multiprecision::sec(boost::multiprecision::catalan()));
+ data.push_back(boost::multiprecision::asin(+boost::multiprecision::catalan() / mp_float("1e30")));
+ data.push_back(boost::multiprecision::asin(-boost::multiprecision::catalan() / mp_float("1e30")));
       }
       virtual const std::vector<mp_float>& control_data(void) const
       {
- static const boost::array<mp_float, 2u> a =
+ static const boost::array<mp_float, 4u> a =
         {{
            mp_float("1.1933383729559773203137729267291947387173342208011247547153095890743890561595544691386633932476257421048110900061166081912943949195747181880197698938173812351027488623304591726956668351876851737682699217189957312877162495237230373808708191601490391769224697378179329863218317580732300824551143583689671403028593009944218611445507878903766448405383719847063127742468033101525589647537043486864948893731"),
            mp_float("1.6419687273531364590567262071166440461685175366204953964739895651486200745161209040937844868647740537903996967626064986560711138637337304241821135325361595693541390424196494707138586320032467383542843973174977685986944349019525021804348293697747650763421720272451832097977353331515326976664205296758687867984902307858016265514207983161159140822122404062357504219549141106987355182424111888131203820022"),
+ mp_float("9.1596559417721901505460351493238411077414937428167213426649824770321202257884602717067499380728515974852534974792725335053169713416495422477659412829135938900234959594014659219497551406645133077883384785850868306010483584350145419323416351657472379419800448382146789912411266712225748380678597136738172111710383925664667554883048994022463260972160151953504181570286917586579688985816103159672576819373e-31"),
+ mp_float("-9.1596559417721901505460351493238411077414937428167213426649824770321202257884602717067499380728515974852534974792725335053169713416495422477659412829135938900234959594014659219497551406645133077883384785850868306010483584350145419323416351657472379419800448382146789912411266712225748380678597136738172111710383925664667554883048994022463260972160151953504181570286917586579688985816103159672576819373e-31"),
         }};
         static const std::vector<mp_float> v(a.begin(), a.end());
         return v;


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