Boost logo

Boost-Commit :

From: john_at_[hidden]
Date: 2007-08-26 13:40:00


Author: johnmaddock
Date: 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
New Revision: 38970
URL: http://svn.boost.org/trac/boost/changeset/38970

Log:
Made max-iterations permitted before we give up a policy rather than a macro or - worse - an ad-hoc value.
At the same time cleared up a lot of gcc-specific signed/unsigned comparison warnings.
Text files modified:
   sandbox/math_toolkit/boost/math/distributions/binomial.hpp | 2
   sandbox/math_toolkit/boost/math/distributions/chi_squared.hpp | 4 +-
   sandbox/math_toolkit/boost/math/distributions/negative_binomial.hpp | 4 +-
   sandbox/math_toolkit/boost/math/distributions/poisson.hpp | 4 +-
   sandbox/math_toolkit/boost/math/distributions/students_t.hpp | 4 +-
   sandbox/math_toolkit/boost/math/policies/error_handling.hpp | 2
   sandbox/math_toolkit/boost/math/policies/policy.hpp | 63 +++++++++++++++++++++++++++++++++++----
   sandbox/math_toolkit/boost/math/special_functions/bessel.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/beta.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_ik.hpp | 16 +++++-----
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy.hpp | 18 ++++++-----
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy_asym.hpp | 2
   sandbox/math_toolkit/boost/math/special_functions/detail/gamma_inva.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inv_ab.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/ellint_rc.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/ellint_rd.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/ellint_rf.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/ellint_rj.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/erf.hpp | 2
   sandbox/math_toolkit/boost/math/special_functions/expm1.hpp | 2
   sandbox/math_toolkit/boost/math/special_functions/gamma.hpp | 4 +-
   sandbox/math_toolkit/boost/math/special_functions/log1p.hpp | 4 +-
   sandbox/math_toolkit/boost/math/tools/config.hpp | 2 -
   sandbox/math_toolkit/boost/math/tools/user.hpp | 13 +++++---
   24 files changed, 115 insertions(+), 63 deletions(-)

Modified: sandbox/math_toolkit/boost/math/distributions/binomial.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/binomial.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/binomial.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -257,7 +257,7 @@
            factor = 2; // trials largish, but in far tails.
 
         typedef typename Policy::discrete_quantile_type discrete_quantile_type;
- boost::uintmax_t max_iter = 1000;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
         return detail::inverse_discrete_quantile(
             dist,
             p,

Modified: sandbox/math_toolkit/boost/math/distributions/chi_squared.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/chi_squared.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/chi_squared.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -303,10 +303,10 @@
 
    detail::df_estimator<RealType, Policy> f(alpha, beta, variance, difference_from_variance);
    tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>());
- boost::uintmax_t max_iter = 10000;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
    std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter, Policy());
    RealType result = r.first + (r.second - r.first) / 2;
- if(max_iter == 10000)
+ if(max_iter == policies::get_max_root_iterations<Policy>())
    {
       policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:"
          " either there is no answer to how many degrees of freedom are required"

Modified: sandbox/math_toolkit/boost/math/distributions/negative_binomial.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/negative_binomial.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/negative_binomial.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -483,7 +483,7 @@
       //
       // Max iterations permitted:
       //
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
       typedef typename Policy::discrete_quantile_type discrete_type;
       return detail::inverse_discrete_quantile(
          dist,
@@ -560,7 +560,7 @@
        //
        // Max iterations permitted:
        //
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
        typedef typename Policy::discrete_quantile_type discrete_type;
        return detail::inverse_discrete_quantile(
           dist,

Modified: sandbox/math_toolkit/boost/math/distributions/poisson.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/poisson.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/poisson.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -487,7 +487,7 @@
       return gamma_q_inva(dist.mean(), p, Policy()) - 1;
       */
       typedef typename Policy::discrete_quantile_type discrete_type;
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
       RealType guess, factor = 8;
       RealType z = dist.mean();
       if(z < 1)
@@ -555,7 +555,7 @@
       return gamma_p_inva(dist.mean(), q, Policy()) -1;
       */
       typedef typename Policy::discrete_quantile_type discrete_type;
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
       RealType guess, factor = 8;
       RealType z = dist.mean();
       if(z < 1)

Modified: sandbox/math_toolkit/boost/math/distributions/students_t.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/students_t.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/students_t.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -274,10 +274,10 @@
 
    detail::sample_size_func<RealType, Policy> f(alpha, beta, sd, difference_from_mean);
    tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>());
- boost::uintmax_t max_iter = 10000;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
    std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter, Policy());
    RealType result = r.first + (r.second - r.first) / 2;
- if(max_iter == 10000)
+ if(max_iter == policies::get_max_root_iterations<Policy>())
    {
       policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:"
          " either there is no answer to how many degrees of freedom are required"

Modified: sandbox/math_toolkit/boost/math/policies/error_handling.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/policies/error_handling.hpp (original)
+++ sandbox/math_toolkit/boost/math/policies/error_handling.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -490,7 +490,7 @@
 template <class Policy>
 inline void check_series_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol)
 {
- if(max_iter >= BOOST_MATH_MAX_ITER)
+ if(max_iter >= policies::get_max_series_iterations<Policy>())
       raise_evaluation_error<boost::uintmax_t>(
          function,
          "Series evaluation exceeded %1% iterations, giving up now.", max_iter, pol);

Modified: sandbox/math_toolkit/boost/math/policies/policy.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/policies/policy.hpp (original)
+++ sandbox/math_toolkit/boost/math/policies/policy.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -73,6 +73,12 @@
 #ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY
 #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true
 #endif
+#ifndef BOOST_MATH_MAX_SERIES_ITERATION_POLICY
+#define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000
+#endif
+#ifndef BOOST_MATH_MAX_ROOT_ITERATION_POLICY
+#define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200
+#endif
 
 #if !defined(__BORLANDC__)
 #define BOOST_MATH_META_INT(type, name, Default)\
@@ -193,6 +199,11 @@
 BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY)
 BOOST_MATH_META_INT(int, digits2, 0)
 //
+// Iterations:
+//
+BOOST_MATH_META_INT(unsigned long, max_series_iterations, BOOST_MATH_MAX_SERIES_ITERATION_POLICY)
+BOOST_MATH_META_INT(unsigned long, max_root_iterations, BOOST_MATH_MAX_ROOT_ITERATION_POLICY)
+//
 // Define the names for each possible policy:
 //
 #define BOOST_MATH_PARAMETER(name)\
@@ -347,7 +358,9 @@
           class A8 = default_policy,
           class A9 = default_policy,
           class A10 = default_policy,
- class A11 = default_policy>
+ class A11 = default_policy,
+ class A12 = default_policy,
+ class A13 = default_policy>
 struct policy
 {
 private:
@@ -365,10 +378,12 @@
    BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A9>::value);
    BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A10>::value);
    BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A11>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A12>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A13>::value);
    //
    // Typelist of the arguments:
    //
- typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11> arg_list;
+ typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list;
 
 public:
    typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, domain_error<> >::type domain_error_type;
@@ -398,6 +413,11 @@
    // Mathematically undefined properties:
    //
    typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type;
+ //
+ // Max iterations:
+ //
+ typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type;
+ typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type;
 };
 //
 // These full specializations are defined to reduce the amount of
@@ -423,6 +443,8 @@
    typedef promote_double<> promote_double_type;
    typedef discrete_quantile<> discrete_quantile_type;
    typedef assert_undefined<> assert_undefined_type;
+ typedef max_series_iterations<> max_series_iterations_type;
+ typedef max_root_iterations<> max_root_iterations_type;
 };
 
 template <>
@@ -444,6 +466,8 @@
    typedef promote_double<false> promote_double_type;
    typedef discrete_quantile<> discrete_quantile_type;
    typedef assert_undefined<> assert_undefined_type;
+ typedef max_series_iterations<> max_series_iterations_type;
+ typedef max_root_iterations<> max_root_iterations_type;
 };
 
 template <class Policy,
@@ -457,11 +481,13 @@
           class A8 = default_policy,
           class A9 = default_policy,
           class A10 = default_policy,
- class A11 = default_policy>
+ class A11 = default_policy,
+ class A12 = default_policy,
+ class A13 = default_policy>
 struct normalise
 {
 private:
- typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11> arg_list;
+ typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list;
    typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, typename Policy::domain_error_type >::type domain_error_type;
    typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, typename Policy::pole_error_type >::type pole_error_type;
    typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, typename Policy::overflow_error_type >::type overflow_error_type;
@@ -488,6 +514,11 @@
    //
    typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type;
    //
+ // Max iterations:
+ //
+ typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type;
+ typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type;
+ //
    // Define a typelist of the policies:
    //
    typedef mpl::vector<
@@ -501,7 +532,9 @@
       promote_float_type,
       promote_double_type,
       discrete_quantile_type,
- assert_undefined_type> result_list;
+ assert_undefined_type,
+ max_series_iterations_type,
+ max_root_iterations_type> result_list;
    //
    // Remove all the policies that are the same as the default:
    //
@@ -509,7 +542,7 @@
    //
    // Pad out the list with defaults:
    //
- typedef typename detail::append_N<reduced_list, default_policy, (12 - ::boost::mpl::size<reduced_list>::value)>::type result_type;
+ typedef typename detail::append_N<reduced_list, default_policy, (14 - ::boost::mpl::size<reduced_list>::value)>::type result_type;
 public:
    typedef policy<
       typename mpl::at<result_type, mpl::int_<0> >::type,
@@ -522,7 +555,9 @@
       typename mpl::at<result_type, mpl::int_<7> >::type,
       typename mpl::at<result_type, mpl::int_<8> >::type,
       typename mpl::at<result_type, mpl::int_<9> >::type,
- typename mpl::at<result_type, mpl::int_<10> >::type > type;
+ typename mpl::at<result_type, mpl::int_<10> >::type,
+ typename mpl::at<result_type, mpl::int_<11> >::type,
+ typename mpl::at<result_type, mpl::int_<12> >::type > type;
 };
 //
 // Full specialisation to speed up compilation of the common case:
@@ -691,6 +726,20 @@
    return detail::digits_imp<T, Policy>(tag_type());
 }
 
+template <class Policy>
+inline unsigned long get_max_series_iterations()
+{
+ typedef typename Policy::max_series_iterations_type iter_type;
+ return iter_type::value;
+}
+
+template <class Policy>
+inline unsigned long get_max_root_iterations()
+{
+ typedef typename Policy::max_root_iterations_type iter_type;
+ return iter_type::value;
+}
+
 namespace detail{
 
 template <class A1,

Modified: sandbox/math_toolkit/boost/math/special_functions/bessel.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/bessel.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/bessel.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -85,7 +85,7 @@
 inline T bessel_j_small_z_series(T v, T x, const Policy& pol)
 {
    bessel_j_small_z_series_term<T, Policy> s(v, x);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
    T result = boost::math::tools::sum_series(s, boost::math::policies::digits<T, Policy>(), max_iter);
    policies::check_series_iterations("boost::math::bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol);
    return result;
@@ -96,7 +96,7 @@
 {
    using namespace std; // ADL of std names
    sph_bessel_j_small_z_series_term<T, Policy> s(v, x);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
    T result = boost::math::tools::sum_series(s, boost::math::policies::digits<T, Policy>(), max_iter);
    policies::check_series_iterations("boost::math::sph_bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol);
    return result * sqrt(constants::pi<T>() / 4);

Modified: sandbox/math_toolkit/boost/math/special_functions/beta.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/beta.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/beta.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -476,7 +476,7 @@
    if(result < tools::min_value<T>())
       return s0; // Safeguard: series can't cope with denorms.
    ibeta_series_t<T> s(a, b, x, result);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
    result = boost::math::tools::sum_series(s, boost::math::policies::digits<T, Policy>(), max_iter, s0);
    policies::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%)", max_iter, pol);
    return result;
@@ -556,7 +556,7 @@
    if(result < tools::min_value<T>())
       return s0; // Safeguard: series can't cope with denorms.
    ibeta_series_t<T> s(a, b, x, result);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
    result = boost::math::tools::sum_series(s, boost::math::policies::digits<T, Policy>(), max_iter, s0);
    policies::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%)", max_iter, pol);
    return result;

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_ik.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_ik.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_ik.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -25,7 +25,7 @@
 {
     T f, h, p, q, coef, sum, sum1, tolerance;
     T a, b, c, d, sigma, gamma1, gamma2;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -62,7 +62,7 @@
 
     // series summation
     tolerance = tools::epsilon<T>();
- for (k = 1; k < BOOST_MATH_MAX_ITER; k++)
+ for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++)
     {
         f = (k * f + p + q) / (k*k - v*v);
         p /= k - v;
@@ -90,7 +90,7 @@
 int CF1_ik(T v, T x, T* fv, const Policy& pol)
 {
     T C, D, f, a, b, delta, tiny, tolerance;
- int k;
+ unsigned long k;
 
     using namespace std;
 
@@ -103,7 +103,7 @@
     tiny = sqrt(tools::min_value<T>());
     C = f = tiny; // b0 = 0, replace with tiny
     D = 0;
- for (k = 1; k < BOOST_MATH_MAX_ITER; k++)
+ for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++)
     {
         a = 1;
         b = 2 * (v + k) / x;
@@ -136,7 +136,7 @@
     using namespace boost::math::constants;
 
     T S, C, Q, D, f, a, b, q, delta, tolerance, current, prev;
- int k;
+ unsigned long k;
 
     // |x| >= |v|, CF2_ik converges rapidly
     // |x| -> 0, CF2_ik fails to converge
@@ -154,7 +154,7 @@
     current = 1; // q1
     Q = C = -a; // Q1 = C1 because q1 = 1
     S = 1 + Q * delta; // S1
- for (k = 2; k < BOOST_MATH_MAX_ITER; k++) // starting from 2
+ for (k = 2; k < policies::get_max_series_iterations<Policy>(); k++) // starting from 2
     {
         // continued fraction f = z1 / z0
         a -= 2 * (k - 1);
@@ -200,7 +200,7 @@
     T u, Iv, Kv, Kv1, Ku, Ku1, fv;
     T W, current, prev, next;
     bool reflect = false;
- int n, k;
+ unsigned n, k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -214,7 +214,7 @@
         v = -v; // v is non-negative from here
         kind |= need_k;
     }
- n = tools::real_cast<int>(v + 0.5f);
+ n = tools::real_cast<unsigned>(v + 0.5f);
     u = v - n; // -1/2 <= u < 1/2
 
     if (x < 0)

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -33,7 +33,7 @@
 {
     T g, h, p, q, f, coef, sum, sum1, tolerance;
     T a, d, e, sigma;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -73,7 +73,7 @@
 
     // series summation
     tolerance = tools::epsilon<T>();
- for (k = 1; k < BOOST_MATH_MAX_ITER; k++)
+ for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++)
     {
         f = (k * f + p + q) / (k*k - v2);
         p /= k - v;
@@ -101,7 +101,8 @@
 int CF1_jy(T v, T x, T* fv, int* sign, const Policy& pol)
 {
     T C, D, f, a, b, delta, tiny, tolerance;
- int k, s = 1;
+ unsigned long k;
+ int s = 1;
 
     using namespace std;
 
@@ -114,7 +115,7 @@
     tiny = sqrt(tools::min_value<T>());
     C = f = tiny; // b0 = 0, replace with tiny
     D = 0.0L;
- for (k = 1; k < BOOST_MATH_MAX_ITER * 100; k++)
+ for (k = 1; k < policies::get_max_series_iterations<Policy>() * 100; k++)
     {
         a = -1;
         b = 2 * (v + k) / x;
@@ -154,7 +155,7 @@
 
     complex_type C, D, f, a, b, delta, one(1);
     T tiny, zero(0.0L);
- int k;
+ unsigned long k;
 
     // |x| >= |v|, CF2_jy converges rapidly
     // |x| -> 0, CF2_jy fails to converge
@@ -166,7 +167,7 @@
     tiny = sqrt(tools::min_value<T>());
     C = f = complex_type(-0.5f/x, 1.0L);
     D = 0;
- for (k = 1; k < BOOST_MATH_MAX_ITER; k++)
+ for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++)
     {
         a = (k - 0.5f)*(k - 0.5f) - v*v;
         if (k == 1)
@@ -205,7 +206,8 @@
     T u, Jv, Ju, Yv, Yv1, Yu, Yu1(0), fv, fu;
     T W, p, q, gamma, current, prev, next;
     bool reflect = false;
- int n, k, s;
+ unsigned n, k;
+ int s;
 
     static const char* function = "boost::math::bessel_jy<%1%>(%1%,%1%)";
 
@@ -219,7 +221,7 @@
         v = -v; // v is non-negative from here
         kind = need_j|need_y; // need both for reflection formula
     }
- n = real_cast<int>(v + 0.5L);
+ n = real_cast<unsigned>(v + 0.5L);
     u = v - n; // -1/2 <= u < 1/2
 
     if (x == 0)

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy_asym.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy_asym.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy_asym.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -244,7 +244,7 @@
 
    T y(c * g), y1(c * h);
 
- for(int k = 1; k < BOOST_MATH_MAX_ITER; ++k)
+ for(int k = 1; k < policies::get_max_series_iterations<Policy>(); ++k)
    {
       f = (k * f + p + q) / (k*k - v*v);
       p /= k - v;

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/gamma_inva.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/gamma_inva.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/gamma_inva.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -131,7 +131,7 @@
    //
    // Max iterations permitted:
    //
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
    //
    // Use our generic derivative-free root finding procedure.
    // We could use Newton steps here, taking the PDF of the
@@ -139,7 +139,7 @@
    // even worse performance-wise than the generic method :-(
    //
    std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, false, tol, max_iter, pol);
- if(max_iter >= 200)
+ if(max_iter >= policies::get_max_root_iterations<Policy>())
       policies::raise_evaluation_error<T>("boost::math::gamma_p_inva<%1%>(%1%, %1%)", "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first, pol);
    return (r.first + r.second) / 2;
 }

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inv_ab.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inv_ab.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inv_ab.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -146,9 +146,9 @@
    //
    // Max iterations permitted:
    //
- boost::uintmax_t max_iter = 200;
+ boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
    std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, swap_ab ? true : false, tol, max_iter, pol);
- if(max_iter >= 200)
+ if(max_iter >= policies::get_max_root_iterations<Policy>())
       policies::raise_evaluation_error<T>("boost::math::ibeta_invab_imp<%1%>(%1%,%1%,%1%)", "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first, pol);
    return (r.first + r.second) / 2;
 }

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_rc.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_rc.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_rc.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -27,7 +27,7 @@
 T ellint_rc_imp(T x, T y, const Policy& pol)
 {
     T value, S, u, lambda, tolerance, prefix;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -74,7 +74,7 @@
         x = (x + lambda) / 4;
         y = (y + lambda) / 4;
         ++k;
- }while(k < BOOST_MATH_MAX_ITER);
+ }while(k < policies::get_max_series_iterations<Policy>());
     // Check to see if we gave up too soon:
     policies::check_series_iterations(function, k, pol);
 

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_rd.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_rd.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_rd.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -26,7 +26,7 @@
 {
     T value, u, lambda, sigma, factor, tolerance;
     T X, Y, Z, EA, EB, EC, ED, EE, S1, S2;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -80,7 +80,7 @@
         z = (z + lambda) / 4;
         ++k;
     }
- while(k < BOOST_MATH_MAX_ITER);
+ while(k < policies::get_max_series_iterations<Policy>());
 
     // Check to see if we gave up too soon:
     policies::check_series_iterations(function, k, pol);

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_rf.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_rf.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_rf.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -27,7 +27,7 @@
 T ellint_rf_imp(T x, T y, T z, const Policy& pol)
 {
     T value, X, Y, Z, E2, E3, u, lambda, tolerance;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -85,7 +85,7 @@
         z = (z + lambda) / 4;
         ++k;
     }
- while(k < BOOST_MATH_MAX_ITER);
+ while(k < policies::get_max_series_iterations<Policy>());
 
     // Check to see if we gave up too soon:
     policies::check_series_iterations(function, k, pol);

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_rj.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_rj.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_rj.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -29,7 +29,7 @@
 {
     T value, u, lambda, alpha, beta, sigma, factor, tolerance;
     T X, Y, Z, P, EA, EB, EC, E2, E3, S1, S2, S3;
- int k;
+ unsigned long k;
 
     using namespace std;
     using namespace boost::math::tools;
@@ -126,7 +126,7 @@
         p = (p + lambda) / 4;
         ++k;
     }
- while(k < BOOST_MATH_MAX_ITER);
+ while(k < policies::get_max_series_iterations<Policy>());
 
     // Check to see if we gave up too soon:
     policies::check_series_iterations(function, k, pol);

Modified: sandbox/math_toolkit/boost/math/special_functions/erf.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/erf.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/erf.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -126,7 +126,7 @@
    if(!invert && (z > detail::erf_asymptotic_limit<T, Policy>()))
    {
       detail::erf_asympt_series_t<T> s(z);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
       result = boost::math::tools::sum_series(s, policies::digits<T, Policy>(), max_iter, 1);
       policies::check_series_iterations("boost::math::erf<%1%>(%1%, %1%)", max_iter, pol);
    }

Modified: sandbox/math_toolkit/boost/math/special_functions/expm1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/expm1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/expm1.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -76,7 +76,7 @@
    if(a < tools::epsilon<T>())
       return x;
    detail::expm1_series<T> s(x);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T result = tools::sum_series(s, policies::digits<T, Policy>(), max_iter);
 #else

Modified: sandbox/math_toolkit/boost/math/special_functions/gamma.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/gamma.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/gamma.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -317,7 +317,7 @@
    // lower incomplete integral. Then divide by tgamma(a)
    // to get the normalised value.
    lower_incomplete_gamma_series<T> s(a, z);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
    int bits = policies::digits<T, Policy>();
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T zero = 0;
@@ -729,7 +729,7 @@
    T result = tgamma1pm1(a, pol) - powm1(x, a, pol);
    result /= a;
    detail::small_gamma2_series<T> s(a, x);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T zero = 0;
    result -= pow(x, a) * tools::sum_series(s, boost::math::policies::digits<T, Policy>(), max_iter, zero);

Modified: sandbox/math_toolkit/boost/math/special_functions/log1p.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/log1p.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/log1p.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -91,7 +91,7 @@
    if(a < tools::epsilon<result_type>())
       return x;
    detail::log1p_series<result_type> s(x);
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    result_type result = tools::sum_series(s, policies::digits<result_type, Policy>(), max_iter);
 #else
@@ -250,7 +250,7 @@
       return -x * x / 2;
    boost::math::detail::log1p_series<T> s(x);
    s();
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+ boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T zero = 0;
    T result = boost::math::tools::sum_series(s, policies::digits<T, Policy>(), max_iter, zero);

Modified: sandbox/math_toolkit/boost/math/tools/config.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/config.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/config.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -7,8 +7,6 @@
 
 #include <boost/math/tools/user.hpp>
 
-#define BOOST_MATH_MAX_ITER 1000000
-
 #if defined(__CYGWIN__) || defined(__FreeBSD__)
 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
 #endif

Modified: sandbox/math_toolkit/boost/math/tools/user.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/user.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/user.hpp 2007-08-26 13:39:53 EDT (Sun, 26 Aug 2007)
@@ -12,11 +12,6 @@
 // This file can be modified by the user to change the default policies.
 // See "Changing the Policy Defaults" in documentation.
 
-//
-// The maximum number of iterations in series evaluations etc:
-//
-// #define BOOST_MATH_MAX_ITER 1000000
-//
 // define this if the platform has no long double functions,
 // or if the long double versions have only double precision:
 //
@@ -84,6 +79,14 @@
 // then do we stop the code from compiling?
 //
 // #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true
+//
+// Maximum series iterstions permitted:
+//
+// #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000
+//
+// Maximum root finding steps permitted:
+//
+// define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200
 
 #endif // BOOST_MATH_TOOLS_USER_HPP
 


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