Boost logo

Boost-Commit :

From: johnmaddock_at_[hidden]
Date: 2007-07-25 07:52:00


Author: johnmaddock
Date: 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
New Revision: 7536
URL: http://svn.boost.org/trac/boost/changeset/7536

Log:
Merged policy code.

Added:
   sandbox/math_toolkit/boost/math/distributions.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/distributions.hpp
   sandbox/math_toolkit/boost/math/distributions/detail/inv_discrete_quantile.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/distributions/detail/inv_discrete_quantile.hpp
   sandbox/math_toolkit/boost/math/distributions/fwd.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/distributions/fwd.hpp
   sandbox/math_toolkit/boost/math/policy/
   sandbox/math_toolkit/boost/math/policy/error_handling.hpp
   sandbox/math_toolkit/boost/math/policy/policy.hpp
   sandbox/math_toolkit/boost/math/special_functions.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/special_functions.hpp
   sandbox/math_toolkit/boost/math/special_functions/detail/lgamma_small.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/special_functions/detail/lgamma_small.hpp
   sandbox/math_toolkit/boost/math/tools/user.hpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/boost/math/tools/user.hpp
   sandbox/math_toolkit/libs/math/doc/policy.qbk
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/libs/math/doc/policy.qbk
   sandbox/math_toolkit/libs/math/test/binomial_quantile.ipp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/libs/math/test/binomial_quantile.ipp
   sandbox/math_toolkit/libs/math/test/negative_binomial_quantile.ipp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/libs/math/test/negative_binomial_quantile.ipp
   sandbox/math_toolkit/libs/math/test/poisson_quantile.ipp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/libs/math/test/poisson_quantile.ipp
   sandbox/math_toolkit/libs/math/test/test_policy.cpp
   sandbox/math_toolkit/libs/math/test/test_policy_sf.cpp
      - copied unchanged from r7522, /sandbox/math_toolkit/policy/libs/math/test/test_policy_sf.cpp
Removed:
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jv.hpp
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kv.hpp
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yv.hpp
   sandbox/math_toolkit/boost/math/tools/error_handling.hpp
   sandbox/math_toolkit/boost/math/tools/evaluation_type.hpp
   sandbox/math_toolkit/libs/math/test/compile_test/tools_error_handling_inc_test.cpp
   sandbox/math_toolkit/libs/math/test/compile_test/tools_evaluation_type_inc_test.cpp
Text files modified:
   sandbox/math_toolkit/boost/math/concepts/real_concept.hpp | 39 +
   sandbox/math_toolkit/boost/math/concepts/std_real_concept.hpp | 15
   sandbox/math_toolkit/boost/math/distributions/bernoulli.hpp | 117 ++--
   sandbox/math_toolkit/boost/math/distributions/beta.hpp | 230 ++++----
   sandbox/math_toolkit/boost/math/distributions/binomial.hpp | 432 ++++++---------
   sandbox/math_toolkit/boost/math/distributions/cauchy.hpp | 140 ++--
   sandbox/math_toolkit/boost/math/distributions/chi_squared.hpp | 140 ++--
   sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp | 27
   sandbox/math_toolkit/boost/math/distributions/detail/derived_accessors.hpp | 14
   sandbox/math_toolkit/boost/math/distributions/exponential.hpp | 120 ++--
   sandbox/math_toolkit/boost/math/distributions/extreme_value.hpp | 104 ++-
   sandbox/math_toolkit/boost/math/distributions/fisher_f.hpp | 175 +++---
   sandbox/math_toolkit/boost/math/distributions/gamma.hpp | 154 +++--
   sandbox/math_toolkit/boost/math/distributions/lognormal.hpp | 120 ++--
   sandbox/math_toolkit/boost/math/distributions/negative_binomial.hpp | 330 +++++++----
   sandbox/math_toolkit/boost/math/distributions/normal.hpp | 72 +-
   sandbox/math_toolkit/boost/math/distributions/pareto.hpp | 216 ++++---
   sandbox/math_toolkit/boost/math/distributions/poisson.hpp | 297 ++++++++---
   sandbox/math_toolkit/boost/math/distributions/rayleigh.hpp | 117 ++--
   sandbox/math_toolkit/boost/math/distributions/students_t.hpp | 143 ++--
   sandbox/math_toolkit/boost/math/distributions/triangular.hpp | 180 +++---
   sandbox/math_toolkit/boost/math/distributions/uniform.hpp | 150 ++--
   sandbox/math_toolkit/boost/math/distributions/weibull.hpp | 167 +++--
   sandbox/math_toolkit/boost/math/special_functions/acosh.hpp | 21
   sandbox/math_toolkit/boost/math/special_functions/asinh.hpp | 8
   sandbox/math_toolkit/boost/math/special_functions/atanh.hpp | 35
   sandbox/math_toolkit/boost/math/special_functions/bessel.hpp | 305 +++++-----
   sandbox/math_toolkit/boost/math/special_functions/beta.hpp | 399 +++++++++-----
   sandbox/math_toolkit/boost/math/special_functions/binomial.hpp | 29
   sandbox/math_toolkit/boost/math/special_functions/cbrt.hpp | 16
   sandbox/math_toolkit/boost/math/special_functions/cos_pi.hpp | 6
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_ik.hpp | 48
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jn.hpp | 6
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy.hpp | 52 +
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jy_asym.hpp | 36
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k0.hpp | 14
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k1.hpp | 14
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kn.hpp | 22
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y0.hpp | 14
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y1.hpp | 10
   sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yn.hpp | 22
   sandbox/math_toolkit/boost/math/special_functions/detail/erf_inv.hpp | 106 ++-
   sandbox/math_toolkit/boost/math/special_functions/detail/gamma_inva.hpp | 40
   sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inv_ab.hpp | 58 +
   sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inverse.hpp | 148 +++--
   sandbox/math_toolkit/boost/math/special_functions/detail/igamma_inverse.hpp | 114 ++-
   sandbox/math_toolkit/boost/math/special_functions/detail/igamma_large.hpp | 41
   sandbox/math_toolkit/boost/math/special_functions/detail/t_distribution_inv.hpp | 83 +-
   sandbox/math_toolkit/boost/math/special_functions/digamma.hpp | 45 +
   sandbox/math_toolkit/boost/math/special_functions/ellint_1.hpp | 69 +
   sandbox/math_toolkit/boost/math/special_functions/ellint_2.hpp | 66 +
   sandbox/math_toolkit/boost/math/special_functions/ellint_3.hpp | 122 ++-
   sandbox/math_toolkit/boost/math/special_functions/ellint_rc.hpp | 36
   sandbox/math_toolkit/boost/math/special_functions/ellint_rd.hpp | 44
   sandbox/math_toolkit/boost/math/special_functions/ellint_rf.hpp | 38
   sandbox/math_toolkit/boost/math/special_functions/ellint_rj.hpp | 57 +
   sandbox/math_toolkit/boost/math/special_functions/erf.hpp | 226 +++++---
   sandbox/math_toolkit/boost/math/special_functions/expm1.hpp | 94 ++-
   sandbox/math_toolkit/boost/math/special_functions/factorials.hpp | 75 +
   sandbox/math_toolkit/boost/math/special_functions/fpclassify.hpp | 3
   sandbox/math_toolkit/boost/math/special_functions/gamma.hpp | 1068 +++++++++++++--------------------------
   sandbox/math_toolkit/boost/math/special_functions/hermite.hpp | 15
   sandbox/math_toolkit/boost/math/special_functions/hypot.hpp | 18
   sandbox/math_toolkit/boost/math/special_functions/laguerre.hpp | 44 +
   sandbox/math_toolkit/boost/math/special_functions/lanczos.hpp | 169 ++---
   sandbox/math_toolkit/boost/math/special_functions/legendre.hpp | 79 +-
   sandbox/math_toolkit/boost/math/special_functions/log1p.hpp | 153 +++-
   sandbox/math_toolkit/boost/math/special_functions/math_fwd.hpp | 641 +++++++++++++++++++++++
   sandbox/math_toolkit/boost/math/special_functions/powm1.hpp | 16
   sandbox/math_toolkit/boost/math/special_functions/sin_pi.hpp | 6
   sandbox/math_toolkit/boost/math/special_functions/sinc.hpp | 14
   sandbox/math_toolkit/boost/math/special_functions/sinhc.hpp | 5
   sandbox/math_toolkit/boost/math/special_functions/spherical_harmonic.hpp | 64 +
   sandbox/math_toolkit/boost/math/special_functions/sqrt1pm1.hpp | 12
   sandbox/math_toolkit/boost/math/tools/config.hpp | 13
   sandbox/math_toolkit/boost/math/tools/minima.hpp | 3
   sandbox/math_toolkit/boost/math/tools/ntl.hpp | 41
   sandbox/math_toolkit/boost/math/tools/precision.hpp | 14
   sandbox/math_toolkit/boost/math/tools/promotion.hpp | 10
   sandbox/math_toolkit/boost/math/tools/remez.hpp | 9
   sandbox/math_toolkit/boost/math/tools/roots.hpp | 22
   sandbox/math_toolkit/boost/math/tools/test.hpp | 17
   sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp | 75 ++
   sandbox/math_toolkit/libs/math/doc/distributions/binomial.qbk | 8
   sandbox/math_toolkit/libs/math/doc/math.qbk | 2
   sandbox/math_toolkit/libs/math/performance/main.cpp | 1
   sandbox/math_toolkit/libs/math/test/Jamfile.v2 | 9
   sandbox/math_toolkit/libs/math/test/compile_test/distribution_concept_check.cpp | 18
   sandbox/math_toolkit/libs/math/test/compile_test/instantiate.hpp | 291 +++++++++-
   sandbox/math_toolkit/libs/math/test/compile_test/std_real_concept_check.cpp | 2
   sandbox/math_toolkit/libs/math/test/hypot_test.cpp | 1
   sandbox/math_toolkit/libs/math/test/log1p_expm1_test.cpp | 6
   sandbox/math_toolkit/libs/math/test/test_bernoulli.cpp | 3
   sandbox/math_toolkit/libs/math/test/test_bessel_i.cpp | 3
   sandbox/math_toolkit/libs/math/test/test_bessel_j.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_bessel_k.cpp | 3
   sandbox/math_toolkit/libs/math/test/test_bessel_y.cpp | 3
   sandbox/math_toolkit/libs/math/test/test_beta.cpp | 8
   sandbox/math_toolkit/libs/math/test/test_binomial.cpp | 65 ++
   sandbox/math_toolkit/libs/math/test/test_binomial_coeff.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_carlson.cpp | 4
   sandbox/math_toolkit/libs/math/test/test_cauchy.cpp | 1
   sandbox/math_toolkit/libs/math/test/test_chi_squared.cpp | 1
   sandbox/math_toolkit/libs/math/test/test_ellint_1.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_ellint_2.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_ellint_3.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_erf.cpp | 12
   sandbox/math_toolkit/libs/math/test/test_error_handling.cpp | 281 +++------
   sandbox/math_toolkit/libs/math/test/test_factorials.cpp | 6
   sandbox/math_toolkit/libs/math/test/test_gamma.cpp | 12
   sandbox/math_toolkit/libs/math/test/test_gamma_dist.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_hermite.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_ibeta.cpp | 10
   sandbox/math_toolkit/libs/math/test/test_ibeta_inv.cpp | 6
   sandbox/math_toolkit/libs/math/test/test_ibeta_inv_ab.cpp | 8
   sandbox/math_toolkit/libs/math/test/test_igamma.cpp | 12
   sandbox/math_toolkit/libs/math/test/test_igamma_inv.cpp | 14
   sandbox/math_toolkit/libs/math/test/test_igamma_inva.cpp | 12
   sandbox/math_toolkit/libs/math/test/test_laguerre.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_legendre.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_negative_binomial.cpp | 75 ++
   sandbox/math_toolkit/libs/math/test/test_poisson.cpp | 68 ++
   sandbox/math_toolkit/libs/math/test/test_rational_instances/test_rational.hpp | 1
   sandbox/math_toolkit/libs/math/test/test_rationals.cpp | 1
   sandbox/math_toolkit/libs/math/test/test_remez.cpp | 6
   sandbox/math_toolkit/libs/math/test/test_roots.cpp | 39
   sandbox/math_toolkit/libs/math/test/test_spherical_harmonic.cpp | 2
   sandbox/math_toolkit/libs/math/test/test_tgamma_ratio.cpp | 11
   sandbox/math_toolkit/libs/math/tools/ibeta_data.cpp | 2
   sandbox/math_toolkit/libs/math/tools/ntl_rr_lanczos.hpp | 13
   130 files changed, 5681 insertions(+), 3886 deletions(-)

Modified: sandbox/math_toolkit/boost/math/concepts/real_concept.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/concepts/real_concept.hpp (original)
+++ sandbox/math_toolkit/boost/math/concepts/real_concept.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -24,6 +24,7 @@
 #include <boost/limits.hpp>
 #include <boost/math/tools/real_cast.hpp>
 #include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/policy.hpp>
 
 #include <ostream>
 #include <istream>
@@ -322,11 +323,15 @@
    return tools::epsilon<long double>();
 }
 
+} // namespace tools
+
+namespace policy{
+
 template <>
-inline int digits<concepts::real_concept>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+inline int digits<concepts::real_concept, policy<> >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
 { // Assume number of significand bits is same as long double,
   // unless std::numeric_limits<T>::is_specialized to provide digits.
- return tools::digits<long double>();
+ return boost::math::policy::digits<long double, boost::math::policy::policy<> >();
    // Note that if numeric_limits real concept is NOT specialized to provide digits10
    // (or max_digits10) then the default precision of 6 decimal digits will be used
    // by Boost test (giving misleading error messages like
@@ -334,7 +339,35 @@
    // and by Boost lexical cast and serialization causing loss of accuracy.
 }
 
-} // namespace tools
+template <>
+inline int digits<concepts::real_concept, policy<detail::forwarding_arg1, detail::forwarding_arg2 > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<real> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<integer_below> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<integer_above> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<integer_outside> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<integer_inside> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+template <>
+inline int digits<concepts::real_concept, policy<discrete_quantile<integer_nearest> > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
+{ return digits<concepts::real_concept, policy<> >(); }
+
+}
 
 } // namespace math
 } // namespace boost

Modified: sandbox/math_toolkit/boost/math/concepts/std_real_concept.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/concepts/std_real_concept.hpp (original)
+++ sandbox/math_toolkit/boost/math/concepts/std_real_concept.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -20,6 +20,7 @@
 #include <boost/limits.hpp>
 #include <boost/math/tools/real_cast.hpp>
 #include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/policy.hpp>
 
 #include <ostream>
 #include <istream>
@@ -328,14 +329,22 @@
    return tools::epsilon<long double>();
 }
 
+} // namespace tools
+
+namespace policy{
+
 template <>
-inline int digits<concepts::std_real_concept>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+inline int digits<concepts::std_real_concept, boost::math::policy::policy<> >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
 { // Assume number of significand bits is same as long double,
   // unless std::numeric_limits<T>::is_specialized to provide digits.
- return tools::digits<long double>();
+ return digits<long double, policy<> >();
 }
+template <>
+inline int digits<concepts::std_real_concept, policy<detail::forwarding_arg1, detail::forwarding_arg2 > >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{ return digits<concepts::std_real_concept, policy<> >(); }
 
-} // namespace tools
+
+}
 
 } // namespace math
 } // namespace boost

Modified: sandbox/math_toolkit/boost/math/distributions/bernoulli.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/bernoulli.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/bernoulli.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -27,6 +27,7 @@
 #ifndef BOOST_MATH_SPECIAL_BERNOULLI_HPP
 #define BOOST_MATH_SPECIAL_BERNOULLI_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/tools/config.hpp>
 #include <boost/math/distributions/complement.hpp> // complements
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
@@ -48,44 +49,43 @@
     namespace bernoulli_detail
     {
       // Common error checking routines for bernoulli distribution functions:
- template <class RealType>
- inline bool check_success_fraction(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p);
+ "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, Policy());
           return false;
         }
         return true;
       }
- template <class RealType>
- inline bool check_dist(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& pol)
       {
- return check_success_fraction(function, p, result);
-
+ return check_success_fraction(function, p, result, Policy());
       }
- template <class RealType>
- inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol)
       {
- if(check_dist(function, p, result) == false)
+ if(check_dist(function, p, result, Policy()) == false)
         {
           return false;
         }
         if(!(boost::math::isfinite)(k) || !((k == 0) || (k == 1)))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Number of successes argument is %1%, but must be 0 or 1 !", k);
+ "Number of successes argument is %1%, but must be 0 or 1 !", k, pol);
           return false;
         }
        return true;
       }
- template <class RealType>
- inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result, const Policy& Pol)
       {
- if(check_dist(function, p, result) && detail::check_probability(function, prob, result) == false)
+ if(check_dist(function, p, result, Policy()) && detail::check_probability(function, prob, result, Policy()) == false)
         {
           return false;
         }
@@ -94,20 +94,21 @@
     } // namespace bernoulli_detail
 
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class bernoulli_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       bernoulli_distribution(RealType p = 0.5) : m_p(p)
       { // Default probability = half suits 'fair' coin tossing
         // where probability of heads == probability of tails.
         RealType result; // of checks.
         bernoulli_detail::check_dist(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::bernoulli_distribution<%1%>::bernoulli_distribution",
           m_p,
- &result);
+ &result, Policy());
       } // bernoulli_distribution constructor.
 
       RealType success_fraction() const
@@ -121,50 +122,50 @@
 
     typedef bernoulli_distribution<double> bernoulli;
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const bernoulli_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const bernoulli_distribution<RealType, Policy>& /* dist */)
     { // Range of permissible values for random variable k = {0, 1}.
       using boost::math::tools::max_value;
       return std::pair<RealType, RealType>(0, 1);
     }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const bernoulli_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const bernoulli_distribution<RealType, Policy>& /* dist */)
     { // Range of supported values for random variable k = {0, 1}.
       // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
       return std::pair<RealType, RealType>(0, 1);
     }
 
- template <class RealType>
- inline RealType mean(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const bernoulli_distribution<RealType, Policy>& dist)
     { // Mean of bernoulli distribution = p (n = 1).
       return dist.success_fraction();
     } // mean
 
     // Rely on dereived_accessors quantile(half)
     //template <class RealType>
- //inline RealType median(const bernoulli_distribution<RealType>& dist)
+ //inline RealType median(const bernoulli_distribution<RealType, Policy>& dist)
     //{ // Median of bernoulli distribution is not defined.
     // return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
     //} // median
 
- template <class RealType>
- inline RealType variance(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const bernoulli_distribution<RealType, Policy>& dist)
     { // Variance of bernoulli distribution =p * q.
       return dist.success_fraction() * (1 - dist.success_fraction());
     } // variance
 
- template <class RealType>
- RealType pdf(const bernoulli_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ RealType pdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType k)
     { // Probability Density/Mass Function.
       BOOST_FPU_EXCEPTION_GUARD
       // Error check:
       RealType result; // of checks.
       if(false == bernoulli_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::pdf(bernoulli_distribution<%1%>, %1%)",
         dist.success_fraction(), // 0 to 1
         k, // 0 or 1
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -179,17 +180,17 @@
       }
     } // pdf
 
- template <class RealType>
- inline RealType cdf(const bernoulli_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ inline RealType cdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType k)
     { // Cumulative Distribution Function Bernoulli.
       RealType p = dist.success_fraction();
       // Error check:
       RealType result;
       if(false == bernoulli_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(bernoulli_distribution<%1%>, %1%)",
         p,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -203,19 +204,19 @@
       }
     } // bernoulli cdf
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<bernoulli_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
     { // Complemented Cumulative Distribution Function bernoulli.
       RealType const& k = c.param;
- bernoulli_distribution<RealType> const& dist = c.dist;
+ bernoulli_distribution<RealType, Policy> const& dist = c.dist;
       RealType p = dist.success_fraction();
       // Error checks:
       RealType result;
       if(false == bernoulli_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(bernoulli_distribution<%1%>, %1%)",
         p,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -229,18 +230,18 @@
       }
     } // bernoulli cdf complement
 
- template <class RealType>
- inline RealType quantile(const bernoulli_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ inline RealType quantile(const bernoulli_distribution<RealType, Policy>& dist, const RealType& p)
     { // Quantile or Percent Point Bernoulli function.
       // Return the number of expected successes k either 0 or 1.
       // for a given probability p.
 
       RealType result; // of error checks:
       if(false == bernoulli_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(bernoulli_distribution<%1%>, %1%)",
         dist.success_fraction(),
         p,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -254,21 +255,21 @@
       }
     } // quantile
 
- template <class RealType>
- inline RealType quantile(const complemented2_type<bernoulli_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
     { // Quantile or Percent Point bernoulli function.
       // Return the number of expected successes k for a given
       // complement of the probability q.
       //
       // Error checks:
       RealType q = c.param;
- const bernoulli_distribution<RealType>& dist = c.dist;
+ const bernoulli_distribution<RealType, Policy>& dist = c.dist;
       RealType result;
       if(false == bernoulli_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(bernoulli_distribution<%1%>, %1%)",
         dist.success_fraction(),
         q,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -283,22 +284,22 @@
       }
     } // quantile complemented.
 
- template <class RealType>
- inline RealType mode(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const bernoulli_distribution<RealType, Policy>& dist)
     {
       return static_cast<RealType>((dist.success_fraction() <= 0.5) ? 0 : 1); // p = 0.5 can be 0 or 1
     }
 
- template <class RealType>
- inline RealType skewness(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const bernoulli_distribution<RealType, Policy>& dist)
     {
       using namespace std;; // Aid ADL for sqrt.
       RealType p = dist.success_fraction();
       return (1 - 2 * p) / sqrt(p * (1 - p));
     }
 
- template <class RealType>
- inline RealType kurtosis_excess(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const bernoulli_distribution<RealType, Policy>& dist)
     {
       RealType p = dist.success_fraction();
       // Note Wolfram says this is kurtosis in text, but gamma2 is the kurtosis excess,
@@ -308,8 +309,8 @@
       return 1 / (1 - p) + 1/p -6;
     }
 
- template <class RealType>
- inline RealType kurtosis(const bernoulli_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const bernoulli_distribution<RealType, Policy>& dist)
     {
       RealType p = dist.success_fraction();
       return 1 / (1 - p) + 1/p -6 + 3;

Modified: sandbox/math_toolkit/boost/math/distributions/beta.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/beta.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/beta.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -24,6 +24,7 @@
 #ifndef BOOST_MATH_DIST_BETA_HPP
 #define BOOST_MATH_DIST_BETA_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/beta.hpp> // for beta.
 #include <boost/math/distributions/complement.hpp> // complements.
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
@@ -45,99 +46,99 @@
     namespace beta_detail
     {
       // Common error checking routines for beta distribution functions:
- template <class RealType>
- inline bool check_alpha(const char* function, const RealType& alpha, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_alpha(const char* function, const RealType& alpha, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(alpha) || (alpha <= 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Alpha argument is %1%, but must be > 0 !", alpha);
+ "Alpha argument is %1%, but must be > 0 !", alpha, pol);
           return false;
         }
         return true;
       } // bool check_alpha
 
- template <class RealType>
- inline bool check_beta(const char* function, const RealType& beta, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_beta(const char* function, const RealType& beta, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(beta) || (beta <= 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Beta argument is %1%, but must be > 0 !", beta);
+ "Beta argument is %1%, but must be > 0 !", beta, pol);
           return false;
         }
         return true;
       } // bool check_beta
 
- template <class RealType>
- inline bool check_prob(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
       {
         if((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Probability argument is %1%, but must be >= 0 and <= 1 !", p);
+ "Probability argument is %1%, but must be >= 0 and <= 1 !", p, pol);
           return false;
         }
         return true;
       } // bool check_prob
 
- template <class RealType>
- inline bool check_x(const char* function, const RealType& x, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_x(const char* function, const RealType& x, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(x) || (x < 0) || (x > 1))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "x argument is %1%, but must be >= 0 and <= 1 !", x);
+ "x argument is %1%, but must be >= 0 and <= 1 !", x, pol);
           return false;
         }
         return true;
       } // bool check_x
 
- template <class RealType>
- inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol)
       { // Check both alpha and beta.
- return check_alpha(function, alpha, result)
- && check_beta(function, beta, result);
+ return check_alpha(function, alpha, result, pol)
+ && check_beta(function, beta, result, pol);
       } // bool check_dist
 
- template <class RealType>
- inline bool check_dist_and_x(const char* function, const RealType& alpha, const RealType& beta, RealType x, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_x(const char* function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol)
       {
- return check_dist(function, alpha, beta, result)
- && check_x(function, x, result);
+ return check_dist(function, alpha, beta, result, pol)
+ && check_x(function, x, result, pol);
       } // bool check_dist_and_x
 
- template <class RealType>
- inline bool check_dist_and_prob(const char* function, const RealType& alpha, const RealType& beta, RealType p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_prob(const char* function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol)
       {
- return check_dist(function, alpha, beta, result)
- && check_prob(function, p, result);
+ return check_dist(function, alpha, beta, result, pol)
+ && check_prob(function, p, result, pol);
       } // bool check_dist_and_prob
 
- template <class RealType>
- inline bool check_mean(const char* function, const RealType& mean, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(mean) || (mean <= 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "mean argument is %1%, but must be > 0 !", mean);
+ "mean argument is %1%, but must be > 0 !", mean, pol);
           return false;
         }
         return true;
       } // bool check_mean
- template <class RealType>
- inline bool check_variance(const char* function, const RealType& variance, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_variance(const char* function, const RealType& variance, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(variance) || (variance <= 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "variance argument is %1%, but must be > 0 !", variance);
+ "variance argument is %1%, but must be > 0 !", variance, pol);
           return false;
         }
         return true;
@@ -148,20 +149,21 @@
     // is deliberately NOT included to avoid a name clash with the beta function.
     // Use beta_distribution<> mybeta(...) to construct type double.
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class beta_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       beta_distribution(RealType alpha = 1, RealType beta = 1) : m_alpha(alpha), m_beta(beta)
       {
         RealType result;
         beta_detail::check_dist(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::beta_distribution<%1%>::beta_distribution",
           m_alpha,
           m_beta,
- &result);
+ &result, Policy());
       } // beta_distribution constructor.
       // Accessor functions:
       RealType alpha() const
@@ -184,13 +186,14 @@
         RealType mean, // Expected value of mean.
         RealType variance) // Expected value of variance.
       {
+ static const char* function = "boost::math::beta_distribution<%1%>::estimate_alpha";
         RealType result; // of error checks.
         if(false ==
           beta_detail::check_mean(
- BOOST_CURRENT_FUNCTION, mean, &result)
+ function, mean, &result, Policy())
           &&
           beta_detail::check_variance(
- BOOST_CURRENT_FUNCTION, variance, &result)
+ function, variance, &result, Policy())
           )
         {
           return result;
@@ -202,13 +205,14 @@
         RealType mean, // Expected value of mean.
         RealType variance) // Expected value of variance.
       {
+ static const char* function = "boost::math::beta_distribution<%1%>::estimate_beta";
         RealType result; // of error checks.
         if(false ==
           beta_detail::check_mean(
- BOOST_CURRENT_FUNCTION, mean, &result)
+ function, mean, &result, Policy())
           &&
           beta_detail::check_variance(
- BOOST_CURRENT_FUNCTION, variance, &result)
+ function, variance, &result, Policy())
           )
         {
           return result;
@@ -224,21 +228,22 @@
         RealType x, // x.
         RealType probability) // cdf
       {
+ static const char* function = "boost::math::beta_distribution<%1%>::estimate_alpha";
         RealType result; // of error checks.
         if(false ==
           beta_detail::check_prob(
- BOOST_CURRENT_FUNCTION, probability, &result)
+ function, probability, &result, Policy())
           &&
           beta_detail::check_beta(
- BOOST_CURRENT_FUNCTION, beta, &result)
+ function, beta, &result, Policy())
           &&
           beta_detail::check_x(
- BOOST_CURRENT_FUNCTION, x, &result)
+ function, x, &result, Policy())
           )
         {
           return result;
         }
- return ibeta_inva(beta, x, probability);
+ return ibeta_inva(beta, x, probability, Policy());
       } // RealType estimate_alpha(beta, a, probability)
 
       static RealType estimate_beta(
@@ -247,73 +252,76 @@
         RealType x, // probability x.
         RealType probability) // probability cdf.
       {
+ static const char* function = "boost::math::beta_distribution<%1%>::estimate_beta";
         RealType result; // of error checks.
         if(false ==
           beta_detail::check_prob(
- BOOST_CURRENT_FUNCTION, probability, &result)
+ function, probability, &result, Policy())
           &&
           beta_detail::check_alpha(
- BOOST_CURRENT_FUNCTION, alpha, &result)
+ function, alpha, &result, Policy())
           &&
           beta_detail::check_x(
- BOOST_CURRENT_FUNCTION, x, &result)
+ function, x, &result, Policy())
           )
         {
           return result;
         }
- return ibeta_invb(alpha, x, probability);
+ return ibeta_invb(alpha, x, probability, Policy());
       } // RealType estimate_beta(alpha, x, probability)
 
     private:
       RealType m_alpha; // Two parameters of the beta distribution.
       RealType m_beta;
- }; // template <class RealType> class beta_distribution
+ }; // template <class RealType, class Policy> class beta_distribution
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const beta_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const beta_distribution<RealType, Policy>& /* dist */)
     { // Range of permissible values for random variable x.
       using boost::math::tools::max_value;
       return std::pair<RealType, RealType>(0, 1);
     }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const beta_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const beta_distribution<RealType, Policy>& /* dist */)
     { // Range of supported values for random variable x.
       // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
       return std::pair<RealType, RealType>(0, 1);
     }
 
- template <class RealType>
- inline RealType mean(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const beta_distribution<RealType, Policy>& dist)
     { // Mean of beta distribution = np.
       return dist.alpha() / (dist.alpha() + dist.beta());
     } // mean
 
- template <class RealType>
- inline RealType variance(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const beta_distribution<RealType, Policy>& dist)
     { // Variance of beta distribution = np(1-p).
       RealType a = dist.alpha();
       RealType b = dist.beta();
       return (a * b) / ((a + b ) * (a + b) * (a + b + 1));
     } // variance
 
- template <class RealType>
- inline RealType mode(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const beta_distribution<RealType, Policy>& dist)
     {
+ static const char* function = "boost::math::mode(beta_distribution<%1%> const&)";
+
       RealType result;
       if ((dist.alpha() <= 1))
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "mode undefined for alpha = %1%, must be > 1!", dist.alpha());
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "mode undefined for alpha = %1%, must be > 1!", dist.alpha(), Policy());
         return result;
       }
 
       if ((dist.beta() <= 1))
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "mode undefined for beta = %1%, must be > 1!", dist.beta());
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "mode undefined for beta = %1%, must be > 1!", dist.beta(), Policy());
         return result;
       }
       RealType a = dist.alpha();
@@ -321,16 +329,16 @@
       return (a-1) / (a + b - 2);
     } // mode
 
- //template <class RealType>
- //inline RealType median(const beta_distribution<RealType>& dist)
+ //template <class RealType, class Policy>
+ //inline RealType median(const beta_distribution<RealType, Policy>& dist)
     //{ // Median of beta distribution is not defined.
- // return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
+ // return tools::domain_error<RealType>(function, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
     //} // median
 
     //But WILL be provided by the derived accessor as quantile(0.5).
 
- template <class RealType>
- inline RealType skewness(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const beta_distribution<RealType, Policy>& dist)
     {
       using namespace std; // ADL of std functions.
       RealType a = dist.alpha();
@@ -338,8 +346,8 @@
       return (2 * (b-a) * sqrt(a + b + 1)) / ((a + b + 2) * sqrt(a * b));
     } // skewness
 
- template <class RealType>
- inline RealType kurtosis_excess(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const beta_distribution<RealType, Policy>& dist)
     {
       RealType a = dist.alpha();
       RealType b = dist.beta();
@@ -349,18 +357,19 @@
       return n / d;
     } // kurtosis_excess
 
- template <class RealType>
- inline RealType kurtosis(const beta_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const beta_distribution<RealType, Policy>& dist)
     {
       return 3 + kurtosis_excess(dist);
     } // kurtosis
 
- template <class RealType>
- inline RealType pdf(const beta_distribution<RealType>& dist, const RealType x)
+ template <class RealType, class Policy>
+ inline RealType pdf(const beta_distribution<RealType, Policy>& dist, const RealType x)
     { // Probability Density/Mass Function.
       BOOST_FPU_EXCEPTION_GUARD
 
- using boost::math::tools::domain_error;
+ static const char* function = "boost::math::pdf(beta_distribution<%1%> const&, %1%)";
+
       using namespace std; // for ADL of std functions
 
       RealType a = dist.alpha();
@@ -369,31 +378,32 @@
       // Argument checks:
       RealType result;
       if(false == beta_detail::check_dist_and_x(
- BOOST_CURRENT_FUNCTION,
+ function,
         a, b, x,
- &result))
+ &result, Policy()))
       {
         return result;
       }
       using boost::math::beta;
- return ibeta_derivative(a, b, x);
+ return ibeta_derivative(a, b, x, Policy());
     } // pdf
 
- template <class RealType>
- inline RealType cdf(const beta_distribution<RealType>& dist, const RealType x)
+ template <class RealType, class Policy>
+ inline RealType cdf(const beta_distribution<RealType, Policy>& dist, const RealType x)
     { // Cumulative Distribution Function beta.
- using boost::math::tools::domain_error;
       using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
+
       RealType a = dist.alpha();
       RealType b = dist.beta();
 
       // Argument checks:
       RealType result;
       if(false == beta_detail::check_dist_and_x(
- BOOST_CURRENT_FUNCTION,
+ function,
         a, b, x,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -406,27 +416,28 @@
       {
         return 1;
       }
- return ibeta(a, b, x);
+ return ibeta(a, b, x, Policy());
     } // beta cdf
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<beta_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
     { // Complemented Cumulative Distribution Function beta.
 
- using boost::math::tools::domain_error;
       using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
+
       RealType const& x = c.param;
- beta_distribution<RealType> const& dist = c.dist;
+ beta_distribution<RealType, Policy> const& dist = c.dist;
       RealType a = dist.alpha();
       RealType b = dist.beta();
 
       // Argument checks:
       RealType result;
       if(false == beta_detail::check_dist_and_x(
- BOOST_CURRENT_FUNCTION,
+ function,
         a, b, x,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -441,11 +452,11 @@
       // Calculate cdf beta using the incomplete beta function.
       // Use of ibeta here prevents cancellation errors in calculating
       // 1 - x if x is very small, perhaps smaller than machine epsilon.
- return ibetac(a, b, x);
+ return ibetac(a, b, x, Policy());
     } // beta cdf
 
- template <class RealType>
- inline RealType quantile(const beta_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ inline RealType quantile(const beta_distribution<RealType, Policy>& dist, const RealType& p)
     { // Quantile or Percent Point beta function or
       // Inverse Cumulative probability distribution function CDF.
       // Return x (0 <= x <= 1),
@@ -455,13 +466,15 @@
       // will be less than or equal to that value
       // is whatever probability you supplied as an argument.
 
+ static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
+
       RealType result; // of argument checks:
       RealType a = dist.alpha();
       RealType b = dist.beta();
       if(false == beta_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
+ function,
         a, b, p,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -474,27 +487,30 @@
       {
         return 1;
       }
- return ibeta_inv(a, b, p);
+ return ibeta_inv(a, b, p, static_cast<RealType*>(0), Policy());
     } // quantile
 
- template <class RealType>
- inline RealType quantile(const complemented2_type<beta_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
     { // Complement Quantile or Percent Point beta function .
       // Return the number of expected x for a given
       // complement of the probability q.
+
+ static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
+
       //
       // Error checks:
       RealType q = c.param;
- const beta_distribution<RealType>& dist = c.dist;
+ const beta_distribution<RealType, Policy>& dist = c.dist;
       RealType result;
       RealType a = dist.alpha();
       RealType b = dist.beta();
       if(false == beta_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
+ function,
         a,
         b,
         q,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -508,7 +524,7 @@
         return 1;
       }
 
- return ibetac_inv(a, b, q);
+ return ibetac_inv(a, b, q, static_cast<RealType*>(0), Policy());
     } // Quantile Complement
 
   } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -80,9 +80,11 @@
 #ifndef BOOST_MATH_SPECIAL_BINOMIAL_HPP
 #define BOOST_MATH_SPECIAL_BINOMIAL_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/beta.hpp> // for incomplete beta.
 #include <boost/math/distributions/complement.hpp> // complements
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
+#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> // error checks
 #include <boost/math/special_functions/fpclassify.hpp> // isnan.
 #include <boost/math/tools/roots.hpp> // for root finding.
 
@@ -98,71 +100,75 @@
 {
   namespace math
   {
+
+ template <class RealType, class Policy>
+ class binomial_distribution;
+
      namespace binomial_detail{
         // common error checking routines for binomial distribution functions:
- template <class RealType>
- inline bool check_N(const char* function, const RealType& N, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_N(const char* function, const RealType& N, RealType* result, const Policy& pol)
         {
            if((N < 0) || !(boost::math::isfinite)(N))
            {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
                   function,
- "Number of Trials argument is %1%, but must be >= 0 !", N);
+ "Number of Trials argument is %1%, but must be >= 0 !", N, pol);
                return false;
            }
            return true;
         }
- template <class RealType>
- inline bool check_success_fraction(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol)
         {
            if((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
            {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
                   function,
- "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p);
+ "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, pol);
                return false;
            }
            return true;
         }
- template <class RealType>
- inline bool check_dist(const char* function, const RealType& N, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& N, const RealType& p, RealType* result, const Policy& pol)
         {
            return check_success_fraction(
- function, p, result)
+ function, p, result, pol)
               && check_N(
- function, N, result);
+ function, N, result, pol);
         }
- template <class RealType>
- inline bool check_dist_and_k(const char* function, const RealType& N, const RealType& p, RealType k, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_k(const char* function, const RealType& N, const RealType& p, RealType k, RealType* result, const Policy& pol)
         {
- if(check_dist(function, N, p, result) == false)
+ if(check_dist(function, N, p, result, pol) == false)
               return false;
            if((k < 0) || !(boost::math::isfinite)(k))
            {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
                   function,
- "Number of Successes argument is %1%, but must be >= 0 !", k);
+ "Number of Successes argument is %1%, but must be >= 0 !", k, pol);
                return false;
            }
            if(k > N)
            {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
                   function,
- "Number of Successes argument is %1%, but must be <= Number of Trials !", k);
+ "Number of Successes argument is %1%, but must be <= Number of Trials !", k, pol);
                return false;
            }
            return true;
         }
- template <class RealType>
- inline bool check_dist_and_prob(const char* function, const RealType& N, RealType p, RealType prob, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_prob(const char* function, const RealType& N, RealType p, RealType prob, RealType* result, const Policy& pol)
         {
- if(check_dist(function, N, p, result) && detail::check_probability(function, prob, result) == false)
+ if(check_dist(function, N, p, result, pol) && detail::check_probability(function, prob, result, pol) == false)
               return false;
            return true;
         }
 
- template <class T>
- T inverse_binomial_cornish_fisher(T n, T sf, T p, T q)
+ template <class T, class Policy>
+ T inverse_binomial_cornish_fisher(T n, T sf, T p, T q, const Policy& pol)
          {
             using namespace std;
             // mean:
@@ -174,7 +180,7 @@
             // kurtosis:
             // T k = (1 - 6 * sf * (1 - sf) ) / (n * sf * (1 - sf));
             // Get the inverse of a std normal distribution:
- T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p) * constants::root_two<T>();
+ T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>();
             // Set the sign:
             if(p < 0.5)
                x = -x;
@@ -196,27 +202,102 @@
             return w;
          }
 
+ template <class RealType, class Policy>
+ RealType quantile_imp(const binomial_distribution<RealType, Policy>& dist, const RealType& p, const RealType& q)
+ { // Quantile or Percent Point Binomial function.
+ // Return the number of expected successes k,
+ // for a given probability p.
+ //
+ // Error checks:
+ using namespace std; // ADL of std names
+ RealType result;
+ RealType trials = dist.trials();
+ RealType success_fraction = dist.success_fraction();
+ if(false == binomial_detail::check_dist_and_prob(
+ "boost::math::quantile(binomial_distribution<%1%> const&, %1%)",
+ trials,
+ success_fraction,
+ p,
+ &result, Policy()))
+ {
+ return result;
+ }
+
+ // Special cases:
+ //
+ if(p == 0)
+ { // There may actually be no answer to this question,
+ // since the probability of zero successes may be non-zero,
+ // but zero is the best we can do:
+ return 0;
+ }
+ if(p == 1)
+ { // Probability of n or fewer successes is always one,
+ // so n is the most sensible answer here:
+ return trials;
+ }
+ if (p <= pow(1 - success_fraction, trials))
+ { // p <= pdf(dist, 0) == cdf(dist, 0)
+ return 0; // So the only reasonable result is zero.
+ } // And root finder would fail otherwise.
+
+ // Solve for quantile numerically:
+ //
+ RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, success_fraction, p, q, Policy());
+ RealType factor = 8;
+ if(trials > 100)
+ factor = 1.01f; // guess is pretty accurate
+ else if((trials > 10) && (trials - 1 > guess) && (guess > 3))
+ factor = 1.15f; // less accurate but OK.
+ else if(trials < 10)
+ {
+ // pretty inaccurate guess in this area:
+ if(guess > trials / 64)
+ {
+ guess = trials / 4;
+ factor = 2;
+ }
+ else
+ guess = trials / 1024;
+ }
+ else
+ factor = 2; // trials largish, but in far tails.
+
+ typedef typename Policy::discrete_quantile_type discrete_quantile_type;
+ boost::uintmax_t max_iter = 1000;
+ return detail::inverse_discrete_quantile(
+ dist,
+ p,
+ q,
+ guess,
+ factor,
+ RealType(1),
+ discrete_quantile_type(),
+ max_iter);
+ } // quantile
+
      }
 
     // typedef binomial_distribution<double> binomial;
     // is deliberately NOT included to avoid a name clash with function.
     //typedef binomial_distribution<double> binomial; // Reserved name of type double.
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class binomial_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       binomial_distribution(RealType n = 1, RealType p = 0.5) : m_n(n), m_p(p)
       { // Default n = 1 is the Bernoulli distribution
         // with equal probability of 'heads' or 'tails.
          RealType r;
          binomial_detail::check_dist(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::binomial_distribution<%1%>::binomial_distribution",
             m_n,
             m_p,
- &r);
+ &r, Policy());
       } // binomial_distribution constructor.
 
       RealType success_fraction() const
@@ -245,13 +326,14 @@
          RealType probability,
          interval_type t = clopper_pearson_exact_interval)
       {
+ static const char* function = "boost::math::binomial_distribution<%1%>::estimate_lower_bound_on_p";
         // Error checks:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, trials, RealType(0), successes, &result)
+ function, trials, RealType(0), successes, &result, Policy())
             &&
            binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION, trials, RealType(0), probability, &result))
+ function, trials, RealType(0), probability, &result, Policy()))
         { return result; }
 
         if(successes == 0)
@@ -260,8 +342,8 @@
         // NOTE!!! The Clopper Pearson formula uses "successes" not
         // "successes+1" as usual to get the lower bound,
         // see http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm
- return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability)
- : ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability);
+ return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability, static_cast<RealType*>(0), Policy())
+ : ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
       }
       static RealType estimate_upper_bound_on_p(
          RealType trials,
@@ -269,20 +351,21 @@
          RealType probability,
          interval_type t = clopper_pearson_exact_interval)
       {
+ static const char* function = "boost::math::binomial_distribution<%1%>::estimate_upper_bound_on_p";
         // Error checks:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, trials, RealType(0), successes, &result)
+ function, trials, RealType(0), successes, &result, Policy())
             &&
            binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION, trials, RealType(0), probability, &result))
+ function, trials, RealType(0), probability, &result, Policy()))
         { return result; }
 
         if(trials == successes)
            return 1;
 
- return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability)
- : ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability);
+ return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability, static_cast<RealType*>(0), Policy())
+ : ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
       }
       // Estimate number of trials parameter:
       //
@@ -295,16 +378,17 @@
          RealType p, // success fraction
          RealType alpha) // risk level
       {
+ static const char* function = "boost::math::binomial_distribution<%1%>::estimate_minimum_number_of_trials";
         // Error checks:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, k, p, k, &result)
+ function, k, p, k, &result, Policy())
             &&
            binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION, k, p, alpha, &result))
+ function, k, p, alpha, &result, Policy()))
         { return result; }
 
- result = ibetac_invb(k + 1, p, alpha); // returns n - k
+ result = ibetac_invb(k + 1, p, alpha, Policy()); // returns n - k
         return result + k;
       }
 
@@ -313,56 +397,56 @@
          RealType p, // success fraction
          RealType alpha) // risk level
       {
+ static const char* function = "boost::math::binomial_distribution<%1%>::estimate_maximum_number_of_trials";
         // Error checks:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, k, p, k, &result)
+ function, k, p, k, &result, Policy())
             &&
            binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION, k, p, alpha, &result))
+ function, k, p, alpha, &result, Policy()))
         { return result; }
 
- result = ibeta_invb(k + 1, p, alpha); // returns n - k
+ result = ibeta_invb(k + 1, p, alpha, Policy()); // returns n - k
         return result + k;
       }
 
     private:
         RealType m_n; // Not sure if this shouldn't be an int?
         RealType m_p; // success_fraction
- }; // template <class RealType> class binomial_distribution
+ }; // template <class RealType, class Policy> class binomial_distribution
 
- template <class RealType>
- const std::pair<RealType, RealType> range(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ const std::pair<RealType, RealType> range(const binomial_distribution<RealType, Policy>& dist)
       { // Range of permissible values for random variable k.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(static_cast<RealType>(0), dist.trials());
       }
 
- template <class RealType>
- const std::pair<RealType, RealType> support(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ const std::pair<RealType, RealType> support(const binomial_distribution<RealType, Policy>& dist)
       { // Range of supported values for random variable k.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         return std::pair<RealType, RealType>(0, dist.trials());
       }
 
- template <class RealType>
- inline RealType mean(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const binomial_distribution<RealType, Policy>& dist)
       { // Mean of Binomial distribution = np.
         return dist.trials() * dist.success_fraction();
       } // mean
 
- template <class RealType>
- inline RealType variance(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const binomial_distribution<RealType, Policy>& dist)
       { // Variance of Binomial distribution = np(1-p).
         return dist.trials() * dist.success_fraction() * (1 - dist.success_fraction());
       } // variance
 
- template <class RealType>
- RealType pdf(const binomial_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ RealType pdf(const binomial_distribution<RealType, Policy>& dist, const RealType k)
       { // Probability Density/Mass Function.
         BOOST_FPU_EXCEPTION_GUARD
 
- using boost::math::tools::domain_error;
         using namespace std; // for ADL of std functions
 
         RealType n = dist.trials();
@@ -370,11 +454,11 @@
         // Error check:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::pdf(binomial_distribution<%1%> const&, %1%)",
            n,
            dist.success_fraction(),
            k,
- &result))
+ &result, Policy()))
         {
            return result;
         }
@@ -415,12 +499,12 @@
         // = ibeta_derivative(k+1, n-k+1, p) / (n+1)
         //
         using boost::math::ibeta_derivative; // a, b, x
- return ibeta_derivative(k+1, n-k+1, dist.success_fraction()) / (n+1);
+ return ibeta_derivative(k+1, n-k+1, dist.success_fraction(), Policy()) / (n+1);
 
       } // pdf
 
- template <class RealType>
- inline RealType cdf(const binomial_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ inline RealType cdf(const binomial_distribution<RealType, Policy>& dist, const RealType k)
       { // Cumulative Distribution Function Binomial.
         // The random variate k is the number of successes in n trials.
         // k argument may be integral, signed, or unsigned, or floating point.
@@ -440,7 +524,6 @@
         // P = I[1-p]( n-k, k+1).
         // = 1 - I[p](k + 1, n - k)
 
- using boost::math::tools::domain_error;
         using namespace std; // for ADL of std functions
 
         RealType n = dist.trials();
@@ -449,11 +532,11 @@
         // Error check:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(binomial_distribution<%1%> const&, %1%)",
            n,
            p,
            k,
- &result))
+ &result, Policy()))
         {
            return result;
         }
@@ -489,11 +572,11 @@
         // beta uses a finite sum internally for integer arguments, so
         // we'll just let it take care of the necessary logic.
         //
- return ibetac(k + 1, n - k, p);
+ return ibetac(k + 1, n - k, p, Policy());
       } // binomial cdf
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<binomial_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c)
       { // Complemented Cumulative Distribution Function Binomial.
         // The random variate k is the number of successes in n trials.
         // k argument may be integral, signed, or unsigned, or floating point.
@@ -513,22 +596,21 @@
         // Q = 1 -I[1-p]( n-k, k+1).
         // = I[p](k + 1, n - k)
 
- using boost::math::tools::domain_error;
         using namespace std; // for ADL of std functions
 
         RealType const& k = c.param;
- binomial_distribution<RealType> const& dist = c.dist;
+ binomial_distribution<RealType, Policy> const& dist = c.dist;
         RealType n = dist.trials();
         RealType p = dist.success_fraction();
 
         // Error checks:
         RealType result;
         if(false == binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(binomial_distribution<%1%> const&, %1%)",
            n,
            p,
            k,
- &result))
+ &result, Policy()))
         {
            return result;
         }
@@ -567,197 +649,23 @@
         // beta uses a finite sum internally for integer arguments, so
         // we'll just let it take care of the necessary logic.
         //
- return ibeta(k + 1, n - k, p);
+ return ibeta(k + 1, n - k, p, Policy());
       } // binomial cdf
 
- namespace detail
- {
- template <class RealType>
- struct binomial_functor
- {
- binomial_functor(const binomial_distribution<RealType>& d, const RealType& target, bool c = false)
- : dist(d), t(target), complement(c) {}
-
- RealType operator()(const RealType k)
- {
- if(k >= dist.trials())
- return 1; // any positive value will do.
- return complement ? t - cdf(boost::math::complement(dist, k)) : cdf(dist, k) - t;
- }
- private:
- const binomial_distribution<RealType>& dist;
- RealType t;
- bool complement;
-
- binomial_functor& operator=(const binomial_functor&);
- }; // struct binomial_functor
- } // namespace detail
-
- template <class RealType>
- RealType quantile(const binomial_distribution<RealType>& dist, const RealType& p)
- { // Quantile or Percent Point Binomial function.
- // Return the number of expected successes k,
- // for a given probability p.
- //
- // Error checks:
- using namespace std; // ADL of std names
- RealType result;
- RealType trials = dist.trials();
- if(false == binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
- trials,
- dist.success_fraction(),
- p,
- &result))
- {
- return result;
- }
-
- // Special cases:
- //
- if(p == 0)
- { // There may actually be no answer to this question,
- // since the probability of zero successes may be non-zero,
- // but zero is the best we can do:
- return 0;
- }
- if(p == 1)
- { // Probability of n or fewer successes is always one,
- // so n is the most sensible answer here:
- return dist.trials();
- }
- if (p <= pow(1 - dist.success_fraction(), trials))
- { // p <= pdf(dist, 0) == cdf(dist, 0)
- return 0; // So the only reasonable result is zero.
- } // And root finder would fail otherwise.
-
- // Solve for quantile numerically:
- //
- RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, dist.success_fraction(), p, 1-p);
- RealType factor = 8;
- if(trials > 100)
- factor = 1.01f; // guess is pretty accurate
- else if((trials > 10) && (trials - 1 > guess) && (guess > 3))
- factor = 1.15f; // less accurate but OK.
- else if(trials < 10)
- {
- // pretty inaccurate guess in this area:
- if(guess > trials / 64)
- {
- guess = trials / 4;
- factor = 2;
- }
- else
- guess = trials / 1024;
- }
- else
- factor = 2; // trials largish, but in far tails.
-
- detail::binomial_functor<RealType> f(dist, p);
- tools::eps_tolerance<RealType> tol(tools::digits<RealType>());
- boost::uintmax_t max_iter = 1000;
- std::pair<RealType, RealType> r = tools::bracket_and_solve_root(
- f,
- guess,
- factor,
- true,
- tol,
- max_iter);
- if(max_iter >= 1000)
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first);
- // return centre point of range found:
- return r.first + (r.second - r.first) / 2;
+ template <class RealType, class Policy>
+ inline RealType quantile(const binomial_distribution<RealType, Policy>& dist, const RealType& p)
+ {
+ return binomial_detail::quantile_imp(dist, p, 1-p);
       } // quantile
 
- template <class RealType>
- RealType quantile(const complemented2_type<binomial_distribution<RealType>, RealType>& c)
- { // Quantile or Percent Point Binomial function.
- // Return the number of expected successes k for a given
- // complement of the probability q.
- //
- // Error checks:
- RealType q = c.param;
- const binomial_distribution<RealType>& dist = c.dist;
- RealType trials = dist.trials();
- RealType result;
- if(false == binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
- trials,
- dist.success_fraction(),
- q,
- &result))
- {
- return result;
- }
-
- // Special cases:
- //
- if(q == 1)
- { // There may actually be no answer to this question,
- // since the probability of zero successes may be non-zero,
- // but zero is the best we can do:
- return 0;
- }
- if(q == 0)
- { // Probability of greater than n successes is always zero,
- // so n is the most sensible answer here:
- return dist.trials();
- }
- if(trials == 1)
- {
- if(-q <= -dist.success_fraction())
- return 0;
- }
- else
- {
- if (-q <= boost::math::expm1(boost::math::log1p(-dist.success_fraction()) * trials))
- { // // q <= cdf(complement(dist, 0)) == pdf(dist, 0)
- return 0; // So the only reasonable result is zero.
- } // And root finder would fail otherwise.
- }
-
- // Need to consider the case where
- //
- // Solve for quantile numerically:
- //
- RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, dist.success_fraction(), 1-q, q);
- RealType factor = 8;
- if(trials > 100)
- factor = 1.01f; // guess is pretty accurate
- else if((trials > 10) && (trials - 1 > guess) && (guess > 3))
- factor = 1.15f; // less accurate but OK.
- else if(trials < 10)
- {
- // pretty inaccurate guess in this area:
- if(guess > trials / 64)
- {
- guess = trials / 4;
- factor = 2;
- }
- else
- guess = trials / 1024;
- }
- else
- factor = 2; // trials largish, but in far tails.
-
- detail::binomial_functor<RealType> f(dist, q, true);
- tools::eps_tolerance<RealType> tol(tools::digits<RealType>());
- boost::uintmax_t max_iter = 1000;
- std::pair<RealType, RealType> r = tools::bracket_and_solve_root(
- f,
- guess,
- factor,
- true,
- tol,
- max_iter);
- if(max_iter >= 1000)
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first);
- // return centre point of range found:
- return r.first + (r.second - r.first) / 2;
+ template <class RealType, class Policy>
+ RealType quantile(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c)
+ {
+ return binomial_detail::quantile_imp(c.dist, 1-c.param, c.param);
       } // quantile
 
- template <class RealType>
- inline RealType mode(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const binomial_distribution<RealType, Policy>& dist)
       {
          using namespace std; // ADL of std functions.
          RealType p = dist.success_fraction();
@@ -765,8 +673,8 @@
          return floor(p * (n + 1));
       }
 
- template <class RealType>
- inline RealType median(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType median(const binomial_distribution<RealType, Policy>& dist)
       { // Bounds for the median of the negative binomial distribution
         // VAN DE VEN R. ; WEBER N. C. ;
         // Univ. Sydney, school mathematics statistics, Sydney N.S.W. 2006, AUSTRALIE
@@ -783,8 +691,8 @@
          return floor(p * n); // Chose the middle value.
       }
 
- template <class RealType>
- inline RealType skewness(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const binomial_distribution<RealType, Policy>& dist)
       {
          using namespace std; // ADL of std functions.
          RealType p = dist.success_fraction();
@@ -792,16 +700,16 @@
          return (1 - 2 * p) / sqrt(n * p * (1 - p));
       }
 
- template <class RealType>
- inline RealType kurtosis(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const binomial_distribution<RealType, Policy>& dist)
       {
          RealType p = dist.success_fraction();
          RealType n = dist.trials();
          return 3 - 6 / n + 1 / (n * p * (1 - p));
       }
 
- template <class RealType>
- inline RealType kurtosis_excess(const binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const binomial_distribution<RealType, Policy>& dist)
       {
          RealType p = dist.success_fraction();
          RealType q = 1 - p;

Modified: sandbox/math_toolkit/boost/math/distributions/cauchy.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/cauchy.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/cauchy.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,6 +8,7 @@
 #ifndef BOOST_STATS_CAUCHY_HPP
 #define BOOST_STATS_CAUCHY_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/distributions/complement.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
@@ -15,7 +16,7 @@
 
 #ifdef BOOST_MSVC
 # pragma warning(push)
-# pragma warning(disable: 4702) // unreachable code (return after domain_error throw).
+# pragma warning(disable: 4702) // unreachable code (return after raise_domain_error throw).
 #endif
 
 #include <utility>
@@ -23,28 +24,28 @@
 namespace boost{ namespace math
 {
 
-template <class RealType>
+template <class RealType, class Policy>
 class cauchy_distribution;
 
 namespace detail
 {
 
-template <class RealType>
-inline bool check_cauchy_scale(const char* func, RealType scale, RealType* result)
+template <class RealType, class Policy>
+inline bool check_cauchy_scale(const char* func, RealType scale, RealType* result, const Policy& pol)
 {
    if(scale <= 0)
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          func,
          "The scale parameter for the Cauchy distribution must be > 0 but got %1%.",
- scale);
+ scale, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
-RealType cdf_imp(const cauchy_distribution<RealType>& dist, const RealType& x, bool complement)
+template <class RealType, class Policy>
+RealType cdf_imp(const cauchy_distribution<RealType, Policy>& dist, const RealType& x, bool complement)
 {
    //
    // This calculates the cdf of the Cauchy distribution and/or its complement.
@@ -72,7 +73,7 @@
    RealType result;
    RealType loc = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale(BOOST_CURRENT_FUNCTION, scale, &result))
+ if(0 == detail::check_cauchy_scale("boost::math::cdf(cauchy<%1%>&, %1%)", scale, &result, Policy()))
       return result;
    RealType mx = -fabs((x - loc) / scale);
 
@@ -85,9 +86,9 @@
    return (((x > loc) != complement) ? 1 - result : result);
 } // cdf
 
-template <class RealType>
+template <class RealType, class Policy>
 RealType quantile_imp(
- const cauchy_distribution<RealType>& dist,
+ const cauchy_distribution<RealType, Policy>& dist,
       const RealType& p,
       bool complement)
 {
@@ -100,19 +101,20 @@
    // mid-point of the distribution. This is either added or subtracted
    // from the location parameter depending on whether `complement` is true.
    //
+ static const char* function = "boost::math::quantile(cauchy<%1%>&, %1%)";
    using namespace std; // for ADL of std functions
    // Special cases:
    if(p == 1)
- return (complement ? -1 : 1) * tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return (complement ? -1 : 1) * policy::raise_overflow_error<RealType>(function, 0, Policy());
    if(p == 0)
- return (complement ? 1 : -1) * tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return (complement ? 1 : -1) * policy::raise_overflow_error<RealType>(function, 0, Policy());
 
    RealType result;
    RealType loc = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale(BOOST_CURRENT_FUNCTION, scale, &result))
+ if(0 == detail::check_cauchy_scale(function, scale, &result, Policy()))
       return result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(0 == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    // argument reduction of p:
@@ -128,17 +130,18 @@
 
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class cauchy_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    cauchy_distribution(RealType a = 0, RealType b = 1)
       : m_a(a), m_hg(b)
    {
       RealType r;
- detail::check_cauchy_scale(BOOST_CURRENT_FUNCTION, b, &r);
+ detail::check_cauchy_scale("boost::math::cauchy<%1%>::cauchy", b, &r, Policy());
    } // cauchy_distribution
 
    RealType location()const
@@ -157,27 +160,27 @@
 
 typedef cauchy_distribution<double> cauchy;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const cauchy_distribution<RealType, Policy>&)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity.
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const cauchy_distribution<RealType, Policy>& )
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
    return std::pair<RealType, RealType>(-tools::max_value<RealType>(), tools::max_value<RealType>()); // - to + infinity.
 }
 
-template <class RealType>
-inline RealType pdf(const cauchy_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const cauchy_distribution<RealType, Policy>& dist, const RealType& x)
 {
    RealType result;
    RealType loc = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale(BOOST_CURRENT_FUNCTION, scale, &result))
+ if(0 == detail::check_cauchy_scale("boost::math::pdf(cauchy<%1%>&, %1%)", scale, &result, Policy()))
       return result;
 
    RealType xs = (x - loc) / scale;
@@ -186,32 +189,32 @@
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const cauchy_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const cauchy_distribution<RealType, Policy>& dist, const RealType& x)
 {
    return detail::cdf_imp(dist, x, false);
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const cauchy_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const cauchy_distribution<RealType, Policy>& dist, const RealType& p)
 {
    return detail::quantile_imp(dist, p, false);
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<cauchy_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c)
 {
    return detail::cdf_imp(c.dist, c.param, true);
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<cauchy_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c)
 {
    return detail::quantile_imp(c.dist, c.param, true);
 }
 
-template <class RealType>
-inline RealType mean(const cauchy_distribution<RealType>& )
+template <class RealType, class Policy>
+inline RealType mean(const cauchy_distribution<RealType, Policy>&)
 { // There is no mean:
 #ifdef BOOST_MATH_COMPILE_FAIL_IF_UNDEFINED
 # ifdef BOOST_MSVC
@@ -220,66 +223,81 @@
       BOOST_STATIC_ASSERT(sizeof(RealType) == 0);
 # endif
 #endif
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ typedef typename Policy::assert_undefined_type assert_type;
+ BOOST_STATIC_ASSERT(assert_type::value == 0);
+
+ return policy::raise_domain_error<RealType>(
+ "boost::math::mean(cauchy<%1%>&)",
       "The Cauchy distribution does not have a mean: "
       "the only possible return value is %1%.",
- std::numeric_limits<RealType>::quiet_NaN());
+ std::numeric_limits<RealType>::quiet_NaN(), Policy());
 }
 
-template <class RealType>
-inline RealType variance(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType variance(const cauchy_distribution<RealType, Policy>& /*dist*/)
 {
    // There is no variance:
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ typedef typename Policy::assert_undefined_type assert_type;
+ BOOST_STATIC_ASSERT(assert_type::value == 0);
+
+ return policy::raise_domain_error<RealType>(
+ "boost::math::variance(cauchy<%1%>&)",
       "The Cauchy distribution does not have a variance: "
       "the only possible return value is %1%.",
- std::numeric_limits<RealType>::quiet_NaN());
+ std::numeric_limits<RealType>::quiet_NaN(), Policy());
 }
 
-template <class RealType>
-inline RealType mode(const cauchy_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const cauchy_distribution<RealType, Policy>& dist)
 {
    return dist.location();
 }
 
-template <class RealType>
-inline RealType median(const cauchy_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const cauchy_distribution<RealType, Policy>& dist)
 {
    return dist.location();
 }
-template <class RealType>
-inline RealType skewness(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType skewness(const cauchy_distribution<RealType, Policy>& /*dist*/)
 {
    // There is no skewness:
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ typedef typename Policy::assert_undefined_type assert_type;
+ BOOST_STATIC_ASSERT(assert_type::value == 0);
+
+ return policy::raise_domain_error<RealType>(
+ "boost::math::skewness(cauchy<%1%>&)",
       "The Cauchy distribution does not have a skewness: "
       "the only possible return value is %1%.",
- std::numeric_limits<RealType>::quiet_NaN()); // infinity?
+ std::numeric_limits<RealType>::quiet_NaN(), Policy()); // infinity?
 }
 
-template <class RealType>
-inline RealType kurtosis(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis(const cauchy_distribution<RealType, Policy>& /*dist*/)
 {
    // There is no kurtosis:
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ typedef typename Policy::assert_undefined_type assert_type;
+ BOOST_STATIC_ASSERT(assert_type::value == 0);
+
+ return policy::raise_domain_error<RealType>(
+ "boost::math::kurtosis(cauchy<%1%>&)",
       "The Cauchy distribution does not have a kurtosis: "
       "the only possible return value is %1%.",
- std::numeric_limits<RealType>::quiet_NaN());
+ std::numeric_limits<RealType>::quiet_NaN(), Policy());
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const cauchy_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const cauchy_distribution<RealType, Policy>& /*dist*/)
 {
    // There is no kurtosis excess:
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ typedef typename Policy::assert_undefined_type assert_type;
+ BOOST_STATIC_ASSERT(assert_type::value == 0);
+
+ return policy::raise_domain_error<RealType>(
+ "boost::math::kurtosis_excess(cauchy<%1%>&)",
       "The Cauchy distribution does not have a kurtosis: "
       "the only possible return value is %1%.",
- std::numeric_limits<RealType>::quiet_NaN());
+ std::numeric_limits<RealType>::quiet_NaN(), Policy());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,6 +8,7 @@
 #ifndef BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP
 #define BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/gamma.hpp> // for incomplete beta.
 #include <boost/math/distributions/complement.hpp> // complements
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
@@ -17,17 +18,18 @@
 
 namespace boost{ namespace math{
 
-template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
 class chi_squared_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    chi_squared_distribution(RealType i) : m_df(i)
    {
       RealType result;
       detail::check_df(
- BOOST_CURRENT_FUNCTION, m_df, &result);
+ "boost::math::chi_squared_distribution<%1%>::chi_squared_distribution", m_df, &result, Policy());
    } // chi_squared_distribution
 
    RealType degrees_of_freedom()const
@@ -52,35 +54,38 @@
 
 typedef chi_squared_distribution<double> chi_squared;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const chi_squared_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const chi_squared_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>()); // 0 to + infinity.
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const chi_squared_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const chi_squared_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
    return std::pair<RealType, RealType>(0, tools::max_value<RealType>()); // 0 to + infinity.
 }
 
-template <class RealType>
-RealType pdf(const chi_squared_distribution<RealType>& dist, const RealType& chi_square)
+template <class RealType, class Policy>
+RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
 {
    using namespace std; // for ADL of std functions
    RealType degrees_of_freedom = dist.degrees_of_freedom();
    // Error check:
    RealType error_result;
+
+ static const char* function = "boost::math::pdf(const chi_squared_distribution<%1%>&, %1%)";
+
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result))
+ function, degrees_of_freedom, &error_result, Policy()))
       return error_result;
 
    if((chi_square < 0) || !(boost::math::isfinite)(chi_square))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Chi Square parameter was %1%, but must be > 0 !", chi_square);
+ return policy::raise_domain_error<RealType>(
+ function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy());
    }
 
    if(chi_square == 0)
@@ -88,8 +93,8 @@
       // Handle special cases:
       if(degrees_of_freedom < 2)
       {
- return tools::overflow_error<RealType>(
- BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(
+ function, 0, Policy());
       }
       else if(degrees_of_freedom == 2)
       {
@@ -101,105 +106,111 @@
       }
    }
 
- return gamma_p_derivative(degrees_of_freedom / 2, chi_square / 2) / 2;
+ return gamma_p_derivative(degrees_of_freedom / 2, chi_square / 2, Policy()) / 2;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const chi_squared_distribution<RealType>& dist, const RealType& chi_square)
+template <class RealType, class Policy>
+inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
 {
    RealType degrees_of_freedom = dist.degrees_of_freedom();
    // Error check:
    RealType error_result;
+ static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";
+
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result))
+ function, degrees_of_freedom, &error_result, Policy()))
       return error_result;
 
    if((chi_square < 0) || !(boost::math::isfinite)(chi_square))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Chi Square parameter was %1%, but must be > 0 !", chi_square);
+ return policy::raise_domain_error<RealType>(
+ function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy());
    }
 
- return boost::math::gamma_p(degrees_of_freedom / 2, chi_square / 2);
+ return boost::math::gamma_p(degrees_of_freedom / 2, chi_square / 2, Policy());
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const chi_squared_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist, const RealType& p)
 {
    RealType degrees_of_freedom = dist.degrees_of_freedom();
+ static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result)
+ function, degrees_of_freedom, &error_result, Policy())
          && detail::check_probability(
- BOOST_CURRENT_FUNCTION, p, &error_result))
+ function, p, &error_result, Policy()))
       return error_result;
 
- return 2 * boost::math::gamma_p_inv(degrees_of_freedom / 2, p);
+ return 2 * boost::math::gamma_p_inv(degrees_of_freedom / 2, p, Policy());
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
 {
    RealType const& degrees_of_freedom = c.dist.degrees_of_freedom();
    RealType const& chi_square = c.param;
+ static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result))
+ function, degrees_of_freedom, &error_result, Policy()))
       return error_result;
 
    if((chi_square < 0) || !(boost::math::isfinite)(chi_square))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Chi Square parameter was %1%, but must be > 0 !", chi_square);
+ return policy::raise_domain_error<RealType>(
+ function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy());
    }
 
- return boost::math::gamma_q(degrees_of_freedom / 2, chi_square / 2);
+ return boost::math::gamma_q(degrees_of_freedom / 2, chi_square / 2, Policy());
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<chi_squared_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
 {
    RealType const& degrees_of_freedom = c.dist.degrees_of_freedom();
    RealType const& q = c.param;
+ static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result)
+ function, degrees_of_freedom, &error_result, Policy())
          && detail::check_probability(
- BOOST_CURRENT_FUNCTION, q, &error_result))
+ function, q, &error_result, Policy()))
       return error_result;
 
- return 2 * boost::math::gamma_q_inv(degrees_of_freedom / 2, q);
+ return 2 * boost::math::gamma_q_inv(degrees_of_freedom / 2, q, Policy());
 }
 
-template <class RealType>
-inline RealType mean(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const chi_squared_distribution<RealType, Policy>& dist)
 { // Mean of Chi-Squared distribution = v.
   return dist.degrees_of_freedom();
 } // mean
 
-template <class RealType>
-inline RealType variance(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const chi_squared_distribution<RealType, Policy>& dist)
 { // Variance of Chi-Squared distribution = 2v.
   return 2 * dist.degrees_of_freedom();
 } // variance
 
-template <class RealType>
-inline RealType mode(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist)
 {
    RealType df = dist.degrees_of_freedom();
+ static const char* function = "boost::math::mode(const chi_squared_distribution<%1%>&)";
    if(df <= 2)
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<RealType>(
+ function,
          "The Chi-Squared distribution only has a mode for degrees of freedom >= 2, but got degrees of freedom = %1%.",
- df);
+ df, Policy());
    return df - 2;
 }
 
-//template <class RealType>
-//inline RealType median(const chi_squared_distribution<RealType>& dist)
+//template <class RealType, class Policy>
+//inline RealType median(const chi_squared_distribution<RealType, Policy>& dist)
 //{ // Median is given by Quantile[dist, 1/2]
 // RealType df = dist.degrees_of_freedom();
 // if(df <= 1)
@@ -211,23 +222,23 @@
 //}
 // Now implemented via quantile(half) in derived accessors.
 
-template <class RealType>
-inline RealType skewness(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const chi_squared_distribution<RealType, Policy>& dist)
 {
    using namespace std; // For ADL
    RealType df = dist.degrees_of_freedom();
    return sqrt (8 / df); // == 2 * sqrt(2 / df);
 }
 
-template <class RealType>
-inline RealType kurtosis(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const chi_squared_distribution<RealType, Policy>& dist)
 {
    RealType df = dist.degrees_of_freedom();
    return 3 + 12 / df;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const chi_squared_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const chi_squared_distribution<RealType, Policy>& dist)
 {
    RealType df = dist.degrees_of_freedom();
    return 12 / df;
@@ -238,7 +249,7 @@
 //
 namespace detail{
 
-template <class RealType>
+template <class RealType, class Policy>
 struct df_estimator
 {
    df_estimator(RealType a, RealType b, RealType variance, RealType delta)
@@ -248,7 +259,7 @@
    {
       if(df <= tools::min_value<RealType>())
          return 1;
- chi_squared_distribution<RealType> cs(df);
+ chi_squared_distribution<RealType, Policy> cs(df);
 
       RealType result;
       if(ratio > 0)
@@ -269,34 +280,35 @@
 
 }
 
-template <class RealType>
-RealType chi_squared_distribution<RealType>::estimate_degrees_of_freedom(
+template <class RealType, class Policy>
+RealType chi_squared_distribution<RealType, Policy>::estimate_degrees_of_freedom(
    RealType difference_from_variance,
    RealType alpha,
    RealType beta,
    RealType variance,
    RealType hint)
 {
+ static const char* function = "boost::math::chi_squared_distribution<%1%>::estimate_degrees_of_freedom(%1%,%1%,%1%,%1%,%1%)";
    // Check for domain errors:
    RealType error_result;
    if(false == detail::check_probability(
- BOOST_CURRENT_FUNCTION, alpha, &error_result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, beta, &error_result))
+ function, alpha, &error_result, Policy())
+ && detail::check_probability(function, beta, &error_result, Policy()))
       return error_result;
 
    if(hint <= 0)
       hint = 1;
 
- detail::df_estimator<RealType> f(alpha, beta, variance, difference_from_variance);
- tools::eps_tolerance<RealType> tol(tools::digits<RealType>());
+ detail::df_estimator<RealType, Policy> f(alpha, beta, variance, difference_from_variance);
+ tools::eps_tolerance<RealType> tol(policy::digits<RealType, Policy>());
    boost::uintmax_t max_iter = 10000;
- std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter);
+ 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)
    {
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "Unable to locate solution in a reasonable time:"
+ policy::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"
- " or the answer is infinite. Current best guess is %1%", result);
+ " or the answer is infinite. Current best guess is %1%", result, Policy());
    }
    return result;
 }

Modified: sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,7 +8,7 @@
 #ifndef BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
 #define BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
 
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 
 #ifdef BOOST_MSVC
@@ -18,43 +18,44 @@
 
 namespace boost{ namespace math{ namespace detail{
 
-template <class RealType>
-inline bool check_probability(const char* function, RealType const& prob, RealType* result)
+template <class RealType, class Policy>
+inline bool check_probability(const char* function, RealType const& prob, RealType* result, const Policy& pol)
 {
    if((prob < 0) || (prob > 1) || !(boost::math::isfinite)(prob))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Probability argument is %1%, but must be >= 0 and <= 1 !", prob);
+ "Probability argument is %1%, but must be >= 0 and <= 1 !", prob, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
-inline bool check_df(const char* function, RealType const& df, RealType* result)
+template <class RealType, class Policy>
+inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
 {
    if((df <= 0) || !(boost::math::isfinite)(df))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Degrees of freedom argument is %1%, but must be > 0 !", df);
+ "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_scale(
       const char* function,
       RealType scale,
- RealType* result)
+ RealType* result,
+ const Policy& pol)
 {
    if((scale < 0) || !(boost::math::isfinite)(scale))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Scale parameter is %1%, but must be > 0 !", scale);
+ "Scale parameter is %1%, but must be > 0 !", scale, pol);
       return false;
    }
    return true;

Modified: sandbox/math_toolkit/boost/math/distributions/detail/derived_accessors.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/detail/derived_accessors.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/detail/derived_accessors.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -60,11 +60,12 @@
 { // hazard function
   // http://www.itl.nist.gov/div898/handbook/eda/section3/eda362.htm#HAZ
    typedef typename Distribution::value_type value_type;
+ typedef typename Distribution::policy_type policy_type;
    value_type p = cdf(complement(dist, x));
    value_type d = pdf(dist, x);
    if(d > p * tools::max_value<value_type>())
- return tools::overflow_error<value_type>(
- BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<value_type>(
+ "boost::math::hazard(const Distribution&, %1%)", 0, policy_type());
    if(d == 0)
    {
       // This protects against 0/0, but is it the right thing to do?
@@ -85,6 +86,7 @@
 inline typename Distribution::value_type coefficient_of_variation(const Distribution& dist)
 {
    typedef typename Distribution::value_type value_type;
+ typedef typename Distribution::policy_type policy_type;
 
    using std::abs;
 
@@ -92,7 +94,7 @@
    value_type d = standard_deviation(dist);
    if((abs(m) < 1) && (d > abs(m) * tools::max_value<value_type>()))
    { // Checks too that m is not zero,
- return tools::overflow_error<value_type>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<value_type>("boost::math::coefficient_of_variation(const Distribution&, %1%)", 0, policy_type());
    }
    return d / m; // so MSVC warning on zerodivide is spurious, and suppressed.
 }
@@ -105,21 +107,18 @@
 inline typename Distribution::value_type pdf(const Distribution& dist, const RealType& x)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return pdf(dist, static_cast<value_type>(x));
 }
 template <class Distribution, class RealType>
 inline typename Distribution::value_type cdf(const Distribution& dist, const RealType& x)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return cdf(dist, static_cast<value_type>(x));
 }
 template <class Distribution, class RealType>
 inline typename Distribution::value_type quantile(const Distribution& dist, const RealType& x)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return quantile(dist, static_cast<value_type>(x));
 }
 /*
@@ -127,7 +126,6 @@
 inline typename Distribution::value_type chf(const Distribution& dist, const RealType& x)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return chf(dist, static_cast<value_type>(x));
 }
 */
@@ -135,7 +133,6 @@
 inline typename Distribution::value_type cdf(const complemented2_type<Distribution, RealType>& c)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return cdf(complement(c.dist, static_cast<value_type>(c.param)));
 }
 
@@ -143,7 +140,6 @@
 inline typename Distribution::value_type quantile(const complemented2_type<Distribution, RealType>& c)
 {
    typedef typename Distribution::value_type value_type;
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<value_type, RealType>::value));
    return quantile(complement(c.dist, static_cast<value_type>(c.param)));
 }
 

Modified: sandbox/math_toolkit/boost/math/distributions/exponential.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/exponential.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/exponential.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -6,6 +6,7 @@
 #ifndef BOOST_STATS_EXPONENTIAL_HPP
 #define BOOST_STATS_EXPONENTIAL_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/special_functions/expm1.hpp>
@@ -26,27 +27,27 @@
 //
 // Error check:
 //
-template <class RealType>
-inline bool verify_lambda(const char* function, RealType l, RealType* presult)
+template <class RealType, class Policy>
+inline bool verify_lambda(const char* function, RealType l, RealType* presult, const Policy& pol)
 {
    if(l <= 0)
    {
- *presult = tools::domain_error<RealType>(
+ *presult = policy::raise_domain_error<RealType>(
          function,
- "The scale parameter \"lambda\" must be > 0, but was: %1%.", l);
+ "The scale parameter \"lambda\" must be > 0, but was: %1%.", l, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
-inline bool verify_exp_x(const char* function, RealType x, RealType* presult)
+template <class RealType, class Policy>
+inline bool verify_exp_x(const char* function, RealType x, RealType* presult, const Policy& pol)
 {
    if(x < 0)
    {
- *presult = tools::domain_error<RealType>(
+ *presult = policy::raise_domain_error<RealType>(
          function,
- "The random variable must be >= 0, but was: %1%.", x);
+ "The random variable must be >= 0, but was: %1%.", x, pol);
       return false;
    }
    return true;
@@ -54,17 +55,18 @@
 
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class exponential_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    exponential_distribution(RealType lambda = 1)
       : m_lambda(lambda)
    {
       RealType err;
- detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &err);
+ detail::verify_lambda("boost::math::exponential_distribution<%1%>::exponential_distribution", lambda, &err, Policy());
    } // exponential_distribution
 
    RealType lambda()const { return m_lambda; }
@@ -75,159 +77,169 @@
 
 typedef exponential_distribution<double> exponential;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const exponential_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const exponential_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const exponential_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::pdf(const exponential_distribution<%1%>&, %1%)";
+
    RealType lambda = dist.lambda();
    RealType result;
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
       return result;
- if(0 == detail::verify_exp_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(0 == detail::verify_exp_x(function, x, &result, Policy()))
       return result;
    result = lambda * exp(-lambda * x);
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const exponential_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const exponential_distribution<%1%>&, %1%)";
+
    RealType result;
    RealType lambda = dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
       return result;
- if(0 == detail::verify_exp_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(0 == detail::verify_exp_x(function, x, &result, Policy()))
       return result;
- result = -boost::math::expm1(-x * lambda);
+ result = -boost::math::expm1(-x * lambda, Policy());
 
    return result;
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const exponential_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const exponential_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const exponential_distribution<%1%>&, %1%)";
+
    RealType result;
    RealType lambda = dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
       return result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(0 == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 0)
       return 0;
    if(p == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- result = -boost::math::log1p(-p) / lambda;
+ result = -boost::math::log1p(-p, Policy()) / lambda;
    return result;
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<exponential_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const exponential_distribution<%1%>&, %1%)";
+
    RealType result;
    RealType lambda = c.dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
       return result;
- if(0 == detail::verify_exp_x(BOOST_CURRENT_FUNCTION, c.param, &result))
+ if(0 == detail::verify_exp_x(function, c.param, &result, Policy()))
       return result;
    result = exp(-c.param * lambda);
 
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<exponential_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const exponential_distribution<%1%>&, %1%)";
+
    RealType result;
    RealType lambda = c.dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
       return result;
 
    RealType q = c.param;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(0 == detail::check_probability(function, q, &result, Policy()))
       return result;
 
    if(q == 1)
       return 0;
    if(q == 0)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
    result = -log(q) / lambda;
    return result;
 }
 
-template <class RealType>
-inline RealType mean(const exponential_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const exponential_distribution<RealType, Policy>& dist)
 {
    RealType result;
    RealType lambda = dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda("boost::math::mean(const exponential_distribution<%1%>&)", lambda, &result, Policy()))
       return result;
    return 1 / lambda;
 }
 
-template <class RealType>
-inline RealType standard_deviation(const exponential_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType standard_deviation(const exponential_distribution<RealType, Policy>& dist)
 {
    RealType result;
    RealType lambda = dist.lambda();
- if(0 == detail::verify_lambda(BOOST_CURRENT_FUNCTION, lambda, &result))
+ if(0 == detail::verify_lambda("boost::math::standard_deviation(const exponential_distribution<%1%>&)", lambda, &result, Policy()))
       return result;
    return 1 / lambda;
 }
 
-template <class RealType>
-inline RealType mode(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType mode(const exponential_distribution<RealType, Policy>& /*dist*/)
 {
    return 0;
 }
 
-template <class RealType>
-inline RealType median(const exponential_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const exponential_distribution<RealType, Policy>& dist)
 {
    using boost::math::constants::ln_two;
    return ln_two<RealType>() / dist.lambda(); // ln(2) / lambda
 }
 
-template <class RealType>
-inline RealType skewness(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType skewness(const exponential_distribution<RealType, Policy>& /*dist*/)
 {
    return 2;
 }
 
-template <class RealType>
-inline RealType kurtosis(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis(const exponential_distribution<RealType, Policy>& /*dist*/)
 {
    return 9;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const exponential_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const exponential_distribution<RealType, Policy>& /*dist*/)
 {
    return 6;
 }

Modified: sandbox/math_toolkit/boost/math/distributions/extreme_value.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/extreme_value.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/extreme_value.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -6,6 +6,7 @@
 #ifndef BOOST_STATS_EXTREME_VALUE_HPP
 #define BOOST_STATS_EXTREME_VALUE_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/special_functions/expm1.hpp>
@@ -33,14 +34,14 @@
 //
 // Error check:
 //
-template <class RealType>
-inline bool verify_scale_b(const char* function, RealType b, RealType* presult)
+template <class RealType, class Policy>
+inline bool verify_scale_b(const char* function, RealType b, RealType* presult, const Policy& pol)
 {
    if(b <= 0)
    {
- *presult = tools::domain_error<RealType>(
+ *presult = policy::raise_domain_error<RealType>(
          function,
- "The scale parameter \"b\" must be > 0, but was: %1%.", b);
+ "The scale parameter \"b\" must be > 0, but was: %1%.", b, pol);
       return false;
    }
    return true;
@@ -48,17 +49,18 @@
 
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class extreme_value_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    extreme_value_distribution(RealType a = 0, RealType b = 1)
       : m_a(a), m_b(b)
    {
       RealType err;
- detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &err);
+ detail::verify_scale_b("boost::math::extreme_value_distribution<%1%>::extreme_value_distribution", b, &err, Policy());
    } // extreme_value_distribution
 
    RealType location()const { return m_a; }
@@ -70,44 +72,44 @@
 
 typedef extreme_value_distribution<double> extreme_value;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const extreme_value_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const extreme_value_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const extreme_value_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const extreme_value_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const extreme_value_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const extreme_value_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
    RealType a = dist.location();
    RealType b = dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b("boost::math::pdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
       return result;
    result = exp((a-x)/b) * exp(-exp((a-x)/b)) / b;
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const extreme_value_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const extreme_value_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
    RealType a = dist.location();
    RealType b = dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
       return result;
 
    result = exp(-exp((a-x)/b));
@@ -115,107 +117,111 @@
    return result;
 } // cdf
 
-template <class RealType>
-RealType quantile(const extreme_value_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+RealType quantile(const extreme_value_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const extreme_value_distribution<%1%>&, %1%)";
+
    RealType a = dist.location();
    RealType b = dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b(function, b, &result, Policy()))
       return result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(0 == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 0)
- return -tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<RealType>(function, 0, Policy());
    if(p == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
    result = a - log(-log(p)) * b;
 
    return result;
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<extreme_value_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<extreme_value_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
    RealType a = c.dist.location();
    RealType b = c.dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
       return result;
 
- result = -boost::math::expm1(-exp((a-c.param)/b));
+ result = -boost::math::expm1(-exp((a-c.param)/b), Policy());
 
    return result;
 }
 
-template <class RealType>
-RealType quantile(const complemented2_type<extreme_value_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+RealType quantile(const complemented2_type<extreme_value_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const extreme_value_distribution<%1%>&, %1%)";
+
    RealType a = c.dist.location();
    RealType b = c.dist.scale();
    RealType q = c.param;
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b(function, b, &result, Policy()))
       return result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(0 == detail::check_probability(function, q, &result, Policy()))
       return result;
 
    if(q == 0)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
    if(q == 1)
- return -tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- result = a - log(-boost::math::log1p(-q)) * b;
+ result = a - log(-boost::math::log1p(-q, Policy())) * b;
 
    return result;
 }
 
-template <class RealType>
-inline RealType mean(const extreme_value_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const extreme_value_distribution<RealType, Policy>& dist)
 {
    RealType a = dist.location();
    RealType b = dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b("boost::math::mean(const extreme_value_distribution<%1%>&)", b, &result, Policy()))
       return result;
    return a + constants::euler<RealType>() * b;
 }
 
-template <class RealType>
-inline RealType standard_deviation(const extreme_value_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType standard_deviation(const extreme_value_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions.
 
    RealType b = dist.scale();
    RealType result;
- if(0 == detail::verify_scale_b(BOOST_CURRENT_FUNCTION, b, &result))
+ if(0 == detail::verify_scale_b("boost::math::standard_deviation(const extreme_value_distribution<%1%>&)", b, &result, Policy()))
       return result;
    return constants::pi<RealType>() * b / sqrt(static_cast<RealType>(6));
 }
 
-template <class RealType>
-inline RealType mode(const extreme_value_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const extreme_value_distribution<RealType, Policy>& dist)
 {
    return dist.location();
 }
 
-template <class RealType>
-inline RealType median(const extreme_value_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const extreme_value_distribution<RealType, Policy>& dist)
 {
   using constants::ln_ln_two;
    return dist.location() - dist.scale() * ln_ln_two<RealType>();
 }
 
-template <class RealType>
-inline RealType skewness(const extreme_value_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType skewness(const extreme_value_distribution<RealType, Policy>& /*dist*/)
 {
    //
    // This is 12 * sqrt(6) * zeta(3) / pi^3:
@@ -224,15 +230,15 @@
    return static_cast<RealType>(1.1395470994046486574927930193898461120875997958366L);
 }
 
-template <class RealType>
-inline RealType kurtosis(const extreme_value_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis(const extreme_value_distribution<RealType, Policy>& /*dist*/)
 {
    // See http://mathworld.wolfram.com/ExtremeValueDistribution.html
    return RealType(27) / 5;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const extreme_value_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const extreme_value_distribution<RealType, Policy>& /*dist*/)
 {
    // See http://mathworld.wolfram.com/ExtremeValueDistribution.html
    return RealType(12) / 5;

Modified: sandbox/math_toolkit/boost/math/distributions/fisher_f.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/fisher_f.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/fisher_f.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,6 +8,7 @@
 #ifndef BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP
 #define BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/beta.hpp> // for incomplete beta.
 #include <boost/math/distributions/complement.hpp> // complements
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
@@ -17,19 +18,21 @@
 
 namespace boost{ namespace math{
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class fisher_f_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    fisher_f_distribution(const RealType& i, const RealType& j) : m_df1(i), m_df2(j)
    {
+ static const char* function = "fisher_f_distribution<%1%>::fisher_f_distribution";
       RealType result;
       detail::check_df(
- BOOST_CURRENT_FUNCTION, m_df1, &result);
+ function, m_df1, &result, Policy());
       detail::check_df(
- BOOST_CURRENT_FUNCTION, m_df2, &result);
+ function, m_df2, &result, Policy());
    } // fisher_f_distribution
 
    RealType degrees_of_freedom1()const
@@ -51,47 +54,48 @@
 
 typedef fisher_f_distribution<double> fisher_f;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const fisher_f_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const fisher_f_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const fisher_f_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const fisher_f_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-RealType pdf(const fisher_f_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+RealType pdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
+ static const char* function = "boost::math::pdf(fisher_f_distribution<%1%> const&, %1%)";
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
 
    if((x < 0) || !(boost::math::isfinite)(x))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Random variable parameter was %1%, but must be > 0 !", x);
+ return policy::raise_domain_error<RealType>(
+ function, "Random variable parameter was %1%, but must be > 0 !", x, Policy());
    }
 
    if(x == 0)
    {
       // special cases:
       if(df1 < 2)
- return tools::overflow_error<RealType>(
- BOOST_CURRENT_FUNCTION, 0);
+ return policy::raise_overflow_error<RealType>(
+ function, 0, Policy());
       else if(df1 == 2)
          return 1;
       else
@@ -111,34 +115,35 @@
    if(v1x > df2)
    {
       result = (df2 * df1) / ((df2 + v1x) * (df2 + v1x));
- result *= ibeta_derivative(df2 / 2, df1 / 2, df2 / (df2 + v1x));
+ result *= ibeta_derivative(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy());
    }
    else
    {
       result = df2 + df1 * x;
       result = (result * df1 - x * df1 * df1) / (result * result);
- result *= ibeta_derivative(df1 / 2, df2 / 2, v1x / (df2 + v1x));
+ result *= ibeta_derivative(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
    }
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const fisher_f_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x)
 {
+ static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)";
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
 
    if((x < 0) || !(boost::math::isfinite)(x))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Random Variable parameter was %1%, but must be > 0 !", x);
+ return policy::raise_domain_error<RealType>(
+ function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy());
    }
 
    RealType v1x = df1 * x;
@@ -152,50 +157,52 @@
    // to switch things around so we're passing 1-z instead.
    //
    return v1x > df2
- ? boost::math::ibetac(df2 / 2, df1 / 2, df2 / (df2 + v1x))
- : boost::math::ibeta(df1 / 2, df2 / 2, v1x / (df2 + v1x));
+ ? boost::math::ibetac(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy())
+ : boost::math::ibeta(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const fisher_f_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const fisher_f_distribution<RealType, Policy>& dist, const RealType& p)
 {
+ static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)";
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result)
+ function, df2, &error_result, Policy())
          && detail::check_probability(
- BOOST_CURRENT_FUNCTION, p, &error_result))
+ function, p, &error_result, Policy()))
       return error_result;
 
    RealType x, y;
 
- x = boost::math::ibeta_inv(df1 / 2, df2 / 2, p, &y);
+ x = boost::math::ibeta_inv(df1 / 2, df2 / 2, p, &y, Policy());
 
    return df2 * x / (df1 * y);
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<fisher_f_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c)
 {
+ static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)";
    RealType df1 = c.dist.degrees_of_freedom1();
    RealType df2 = c.dist.degrees_of_freedom2();
    RealType x = c.param;
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
 
    if((x < 0) || !(boost::math::isfinite)(x))
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Random Variable parameter was %1%, but must be > 0 !", x);
+ return policy::raise_domain_error<RealType>(
+ function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy());
    }
 
    RealType v1x = df1 * x;
@@ -209,104 +216,109 @@
    // to switch things around so we're passing 1-z instead.
    //
    return v1x > df2
- ? boost::math::ibeta(df2 / 2, df1 / 2, df2 / (df2 + v1x))
- : boost::math::ibetac(df1 / 2, df2 / 2, v1x / (df2 + v1x));
+ ? boost::math::ibeta(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy())
+ : boost::math::ibetac(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<fisher_f_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c)
 {
+ static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)";
    RealType df1 = c.dist.degrees_of_freedom1();
    RealType df2 = c.dist.degrees_of_freedom2();
    RealType p = c.param;
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result)
+ function, df2, &error_result, Policy())
          && detail::check_probability(
- BOOST_CURRENT_FUNCTION, p, &error_result))
+ function, p, &error_result, Policy()))
       return error_result;
 
    RealType x, y;
 
- x = boost::math::ibetac_inv(df1 / 2, df2 / 2, p, &y);
+ x = boost::math::ibetac_inv(df1 / 2, df2 / 2, p, &y, Policy());
 
    return df2 * x / (df1 * y);
 }
 
-template <class RealType>
-inline RealType mean(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const fisher_f_distribution<RealType, Policy>& dist)
 { // Mean of F distribution = v.
+ static const char* function = "boost::math::mean(fisher_f_distribution<%1%> const&)";
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
    if(df2 <= 2)
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mean.", df2);
+ return policy::raise_domain_error<RealType>(
+ function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mean.", df2, Policy());
    }
    return df2 / (df2 - 2);
 } // mean
 
-template <class RealType>
-inline RealType variance(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const fisher_f_distribution<RealType, Policy>& dist)
 { // Variance of F distribution.
+ static const char* function = "boost::math::variance(fisher_f_distribution<%1%> const&)";
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
    if(df2 <= 4)
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Second degree of freedom was %1% but must be > 4 in order for the distribution to have a valid variance.", df2);
+ return policy::raise_domain_error<RealType>(
+ function, "Second degree of freedom was %1% but must be > 4 in order for the distribution to have a valid variance.", df2, Policy());
    }
    return 2 * df2 * df2 * (df1 + df2 - 2) / (df1 * (df2 - 2) * (df2 - 2) * (df2 - 4));
 } // variance
 
-template <class RealType>
-inline RealType mode(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const fisher_f_distribution<RealType, Policy>& dist)
 {
+ static const char* function = "boost::math::mode(fisher_f_distribution<%1%> const&)";
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
    if(df2 <= 2)
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2);
+ return policy::raise_domain_error<RealType>(
+ function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy());
    }
    return df2 * (df1 - 2) / (df1 * (df2 + 2));
 }
 
-//template <class RealType>
-//inline RealType median(const fisher_f_distribution<RealType>& dist)
+//template <class RealType, class Policy>
+//inline RealType median(const fisher_f_distribution<RealType, Policy>& dist)
 //{ // Median of Fisher F distribution is not defined.
 // return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
 // } // median
 
 // Now implemented via quantile(half) in derived accessors.
 
-template <class RealType>
-inline RealType skewness(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const fisher_f_distribution<RealType, Policy>& dist)
 {
+ static const char* function = "boost::math::skewness(fisher_f_distribution<%1%> const&)";
    using namespace std; // ADL of std names
    // See http://mathworld.wolfram.com/F-Distribution.html
    RealType df1 = dist.degrees_of_freedom1();
@@ -314,44 +326,45 @@
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
    if(df2 <= 6)
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Second degree of freedom was %1% but must be > 6 in order for the distribution to have a skewness.", df2);
+ return policy::raise_domain_error<RealType>(
+ function, "Second degree of freedom was %1% but must be > 6 in order for the distribution to have a skewness.", df2, Policy());
    }
    return 2 * (df2 + 2 * df1 - 2) * sqrt((2 * df2 - 8) / (df1 * (df2 + df1 - 2))) / (df2 - 6);
 }
 
-template <class RealType>
-RealType kurtosis_excess(const fisher_f_distribution<RealType>& dist);
+template <class RealType, class Policy>
+RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist);
 
-template <class RealType>
-inline RealType kurtosis(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const fisher_f_distribution<RealType, Policy>& dist)
 {
    return 3 + kurtosis_excess(dist);
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const fisher_f_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist)
 {
+ static const char* function = "boost::math::kurtosis_excess(fisher_f_distribution<%1%> const&)";
    // See http://mathworld.wolfram.com/F-Distribution.html
    RealType df1 = dist.degrees_of_freedom1();
    RealType df2 = dist.degrees_of_freedom2();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, df1, &error_result)
+ function, df1, &error_result, Policy())
          && detail::check_df(
- BOOST_CURRENT_FUNCTION, df2, &error_result))
+ function, df2, &error_result, Policy()))
       return error_result;
    if(df2 <= 8)
    {
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION, "Second degree of freedom was %1% but must be > 8 in order for the distribution to have a kutosis.", df2);
+ return policy::raise_domain_error<RealType>(
+ function, "Second degree of freedom was %1% but must be > 8 in order for the distribution to have a kutosis.", df2, Policy());
    }
    RealType df2_2 = df2 * df2;
    RealType df1_2 = df1 * df1;

Modified: sandbox/math_toolkit/boost/math/distributions/gamma.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/gamma.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/gamma.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 // http://mathworld.wolfram.com/GammaDistribution.html
 // http://en.wikipedia.org/wiki/Gamma_distribution
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/distributions/complement.hpp>
@@ -21,61 +22,62 @@
 namespace detail
 {
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_gamma_shape(
       const char* function,
       RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
    if((shape <= 0) || !(boost::math::isfinite)(shape))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Shape parameter is %1%, but must be > 0 !", shape);
+ "Shape parameter is %1%, but must be > 0 !", shape, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_gamma_x(
       const char* function,
       RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
    if((x < 0) || !(boost::math::isfinite)(x))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Random variate is %1% but must be >= 0 !", x);
+ "Random variate is %1% but must be >= 0 !", x, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_gamma(
       const char* function,
       RealType scale,
       RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
- return check_scale(function, scale, result) && check_gamma_shape(function, shape, result);
+ return check_scale(function, scale, result, pol) && check_gamma_shape(function, shape, result, pol);
 }
 
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class gamma_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    gamma_distribution(RealType shape, RealType scale = 1)
       : m_shape(shape), m_scale(scale)
    {
       RealType result;
- detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result);
+ detail::check_gamma("boost::math::gamma_distribution<%1%>::gamma_distribution", scale, shape, &result, Policy());
    }
 
    RealType shape()const
@@ -97,218 +99,238 @@
 
 // NO typedef because of clash with name of gamma function.
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const gamma_distribution<RealType>& /* dist */)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const gamma_distribution<RealType, Policy>& /* dist */)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const gamma_distribution<RealType>& /* dist */)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const gamma_distribution<RealType, Policy>& /* dist */)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const gamma_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const gamma_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::pdf(const gamma_distribution<%1%>&, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_gamma_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_gamma_x(function, x, &result, Policy()))
       return result;
 
    if(x == 0)
    {
       return 0;
    }
- result = gamma_p_derivative(shape, x / scale) / scale;
+ result = gamma_p_derivative(shape, x / scale, Policy()) / scale;
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const gamma_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const gamma_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const gamma_distribution<%1%>&, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_gamma_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_gamma_x(function, x, &result, Policy()))
       return result;
 
- result = boost::math::gamma_p(shape, x / scale);
+ result = boost::math::gamma_p(shape, x / scale, Policy());
    return result;
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const gamma_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const gamma_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(false == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- result = gamma_p_inv(shape, p) * scale;
+ result = gamma_p_inv(shape, p, Policy()) * scale;
 
    return result;
 }
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<gamma_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<gamma_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)";
+
    RealType shape = c.dist.shape();
    RealType scale = c.dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_gamma_x(BOOST_CURRENT_FUNCTION, c.param, &result))
+ if(false == detail::check_gamma_x(function, c.param, &result, Policy()))
       return result;
 
- result = gamma_q(shape, c.param / scale);
+ result = gamma_q(shape, c.param / scale, Policy());
 
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<gamma_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<gamma_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)";
+
    RealType shape = c.dist.shape();
    RealType scale = c.dist.scale();
    RealType q = c.param;
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(false == detail::check_probability(function, q, &result, Policy()))
       return result;
 
    if(q == 0)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- result = gamma_q_inv(shape, q) * scale;
+ result = gamma_q_inv(shape, q, Policy()) * scale;
 
    return result;
 }
 
-template <class RealType>
-inline RealType mean(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const gamma_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::mean(const gamma_distribution<%1%>&)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
 
    result = shape * scale;
    return result;
 }
 
-template <class RealType>
-inline RealType variance(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const gamma_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::variance(const gamma_distribution<%1%>&)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
 
    result = shape * scale * scale;
    return result;
 }
 
-template <class RealType>
-inline RealType mode(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const gamma_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::mode(const gamma_distribution<%1%>&)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
 
    if(shape < 1)
- return tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<RealType>(
+ function,
          "The mode of the gamma distribution is only defined for values of the shape parameter >= 1, but got %1%.",
- shape);
+ shape, Policy());
 
    result = (shape - 1) * scale;
    return result;
 }
 
-//template <class RealType>
-//inline RealType median(const gamma_distribution<RealType>& dist)
+//template <class RealType, class Policy>
+//inline RealType median(const gamma_distribution<RealType, Policy>& dist)
 //{ // Rely on default definition in derived accessors.
 //}
 
-template <class RealType>
-inline RealType skewness(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const gamma_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::skewness(const gamma_distribution<%1%>&)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
 
    result = 2 / sqrt(shape);
    return result;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const gamma_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::kurtosis_excess(const gamma_distribution<%1%>&)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_gamma(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
       return result;
 
    result = 6 / shape;
    return result;
 }
 
-template <class RealType>
-inline RealType kurtosis(const gamma_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const gamma_distribution<RealType, Policy>& dist)
 {
    return kurtosis_excess(dist) + 3;
 }

Modified: sandbox/math_toolkit/boost/math/distributions/lognormal.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/lognormal.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/lognormal.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 // http://mathworld.wolfram.com/LogNormalDistribution.html
 // http://en.wikipedia.org/wiki/Lognormal_distribution
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/distributions/normal.hpp>
 #include <boost/math/special_functions/expm1.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
@@ -21,17 +22,17 @@
 namespace detail
 {
 
- template <class RealType>
+ template <class RealType, class Policy>
   inline bool check_lognormal_x(
         const char* function,
         RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
   {
      if((x < 0) || !(boost::math::isfinite)(x))
      {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
            function,
- "Random variate is %1% but must be >= 0 !", x);
+ "Random variate is %1% but must be >= 0 !", x, pol);
         return false;
      }
      return true;
@@ -40,17 +41,18 @@
 } // namespace detail
 
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class lognormal_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    lognormal_distribution(RealType location = 0, RealType scale = 1)
       : m_location(location), m_scale(scale)
    {
       RealType result;
- detail::check_scale(BOOST_CURRENT_FUNCTION, scale, &result);
+ detail::check_scale("boost::math::lognormal_distribution<%1%>::lognormal_distribution", scale, &result, Policy());
    }
 
    RealType location()const
@@ -72,33 +74,35 @@
 
 typedef lognormal_distribution<double> lognormal;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const lognormal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const lognormal_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x is >0 to +infinity.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const lognormal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const lognormal_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-RealType pdf(const lognormal_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+RealType pdf(const lognormal_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
    RealType mu = dist.location();
    RealType sigma = dist.scale();
 
+ static const char* function = "boost::math::pdf(const lognormal_distribution<%1%>&, %1%)";
+
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale(function, sigma, &result, Policy()))
       return result;
- if(0 == detail::check_lognormal_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(0 == detail::check_lognormal_x(function, x, &result, Policy()))
       return result;
 
    if(x == 0)
@@ -114,76 +118,84 @@
    return result;
 }
 
-template <class RealType>
-inline RealType cdf(const lognormal_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const lognormal_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)";
+
    RealType result;
- if(0 == detail::check_lognormal_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(0 == detail::check_lognormal_x(function, x, &result, Policy()))
       return result;
 
    if(x == 0)
       return 0;
 
- normal_distribution<RealType> norm(dist.location(), dist.scale());
+ normal_distribution<RealType, Policy> norm(dist.location(), dist.scale());
    return cdf(norm, log(x));
 }
 
-template <class RealType>
-inline RealType quantile(const lognormal_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const lognormal_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)";
+
    RealType result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(0 == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 0)
       return 0;
    if(p == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- normal_distribution<RealType> norm(dist.location(), dist.scale());
+ normal_distribution<RealType, Policy> norm(dist.location(), dist.scale());
    return exp(quantile(norm, p));
 }
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<lognormal_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<lognormal_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)";
+
    RealType result;
- if(0 == detail::check_lognormal_x(BOOST_CURRENT_FUNCTION, c.param, &result))
+ if(0 == detail::check_lognormal_x(function, c.param, &result, Policy()))
       return result;
 
    if(c.param == 0)
       return 1;
 
- normal_distribution<RealType> norm(c.dist.location(), c.dist.scale());
+ normal_distribution<RealType, Policy> norm(c.dist.location(), c.dist.scale());
    return cdf(complement(norm, log(c.param)));
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<lognormal_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<lognormal_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)";
+
    RealType result;
- if(0 == detail::check_probability(BOOST_CURRENT_FUNCTION, c.param, &result))
+ if(0 == detail::check_probability(function, c.param, &result, Policy()))
       return result;
 
    if(c.param == 1)
       return 0;
    if(c.param == 0)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- normal_distribution<RealType> norm(c.dist.location(), c.dist.scale());
+ normal_distribution<RealType, Policy> norm(c.dist.location(), c.dist.scale());
    return exp(quantile(complement(norm, c.param)));
 }
 
-template <class RealType>
-inline RealType mean(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -191,14 +203,14 @@
    RealType sigma = dist.scale();
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::mean(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
    return exp(mu + sigma * sigma / 2);
 }
 
-template <class RealType>
-inline RealType variance(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -206,14 +218,14 @@
    RealType sigma = dist.scale();
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::variance(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
- return boost::math::expm1(sigma * sigma) * exp(2 * mu + sigma * sigma);
+ return boost::math::expm1(sigma * sigma, Policy()) * exp(2 * mu + sigma * sigma);
 }
 
-template <class RealType>
-inline RealType mode(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -221,22 +233,22 @@
    RealType sigma = dist.scale();
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::mode(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
    return exp(mu - sigma * sigma);
 }
 
-template <class RealType>
-inline RealType median(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
    RealType mu = dist.location();
    return exp(mu); // e^mu
 }
 
-template <class RealType>
-inline RealType skewness(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -247,14 +259,14 @@
    RealType ess = exp(ss);
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::skewness(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
- return (ess + 2) * sqrt(boost::math::expm1(ss));
+ return (ess + 2) * sqrt(boost::math::expm1(ss, Policy()));
 }
 
-template <class RealType>
-inline RealType kurtosis(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -263,14 +275,14 @@
    RealType ss = sigma * sigma;
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::kurtosis(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
    return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 3;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const lognormal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const lognormal_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
@@ -279,7 +291,7 @@
    RealType ss = sigma * sigma;
 
    RealType result;
- if(0 == detail::check_scale(BOOST_CURRENT_FUNCTION, sigma, &result))
+ if(0 == detail::check_scale("boost::math::kurtosis_excess(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
 
    return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 6;

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -39,11 +39,13 @@
 #ifndef BOOST_MATH_SPECIAL_NEGATIVE_BINOMIAL_HPP
 #define BOOST_MATH_SPECIAL_NEGATIVE_BINOMIAL_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/beta.hpp> // for ibeta(a, b, x) == Ix(a, b).
 #include <boost/math/distributions/complement.hpp> // complement.
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks domain_error & logic_error.
 #include <boost/math/special_functions/fpclassify.hpp> // isnan.
 #include <boost/math/tools/roots.hpp> // for root finding.
+#include <boost/math/distributions/detail/inv_discrete_quantile.hpp>
 
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/type_traits/is_integral.hpp>
@@ -66,57 +68,57 @@
     namespace negative_binomial_detail
     {
       // Common error checking routines for negative binomial distribution functions:
- template <class RealType>
- inline bool check_successes(const char* function, const RealType& r, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_successes(const char* function, const RealType& r, RealType* result, const Policy& pol)
       {
         if( !(boost::math::isfinite)(r) || (r <= 0) )
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Number of successes argument is %1%, but must be > 0 !", r);
+ "Number of successes argument is %1%, but must be > 0 !", r, pol);
           return false;
         }
         return true;
       }
- template <class RealType>
- inline bool check_success_fraction(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol)
       {
         if( !(boost::math::isfinite)(p) || (p < 0) || (p > 1) )
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p);
+ "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, pol);
           return false;
         }
         return true;
       }
- template <class RealType>
- inline bool check_dist(const char* function, const RealType& r, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& r, const RealType& p, RealType* result, const Policy& pol)
       {
- return check_success_fraction(function, p, result)
- && check_successes(function, r, result);
+ return check_success_fraction(function, p, result, pol)
+ && check_successes(function, r, result, pol);
       }
- template <class RealType>
- inline bool check_dist_and_k(const char* function, const RealType& r, const RealType& p, RealType k, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_k(const char* function, const RealType& r, const RealType& p, RealType k, RealType* result, const Policy& pol)
       {
- if(check_dist(function, r, p, result) == false)
+ if(check_dist(function, r, p, result, pol) == false)
         {
           return false;
         }
         if( !(boost::math::isfinite)(k) || (k < 0) )
         { // Check k failures.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Number of failures argument is %1%, but must be >= 0 !", k);
+ "Number of failures argument is %1%, but must be >= 0 !", k, pol);
           return false;
         }
         return true;
       } // Check_dist_and_k
 
- template <class RealType>
- inline bool check_dist_and_prob(const char* function, const RealType& r, RealType p, RealType prob, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_prob(const char* function, const RealType& r, RealType p, RealType prob, RealType* result, const Policy& pol)
       {
- if(check_dist(function, r, p, result) && detail::check_probability(function, prob, result) == false)
+ if(check_dist(function, r, p, result, pol) && detail::check_probability(function, prob, result, pol) == false)
         {
           return false;
         }
@@ -124,20 +126,21 @@
       } // check_dist_and_prob
     } // namespace negative_binomial_detail
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class negative_binomial_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       negative_binomial_distribution(RealType r, RealType p) : m_r(r), m_p(p)
       { // Constructor.
         RealType result;
         negative_binomial_detail::check_dist(
- BOOST_CURRENT_FUNCTION,
+ "negative_binomial_distribution<%1%>::negative_binomial_distribution",
           m_r, // Check successes r > 0.
           m_p, // Check success_fraction 0 <= p <= 1.
- &result);
+ &result, Policy());
       } // negative_binomial_distribution constructor.
 
       // Private data getter class member functions.
@@ -155,11 +158,12 @@
         RealType successes,
         RealType alpha) // alpha 0.05 equivalent to 95% for one-sided test.
       {
+ static const char* function = "boost::math::negative_binomial<%1%>::estimate_lower_bound_on_p";
         RealType result; // of error checks.
         RealType failures = trials - successes;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, alpha, &result)
+ if(false == detail::check_probability(function, alpha, &result, Policy())
           && negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, successes, RealType(0), failures, &result))
+ function, successes, RealType(0), failures, &result, Policy()))
         {
           return result;
         }
@@ -171,7 +175,7 @@
         // Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY
         // http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
         //
- return ibeta_inv(successes, failures + 1, alpha);
+ return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(0), Policy());
       } // estimate_lower_bound_on_p
 
       static RealType estimate_upper_bound_on_p(
@@ -179,11 +183,12 @@
         RealType successes,
         RealType alpha) // alpha 0.05 equivalent to 95% for one-sided test.
       {
+ static const char* function = "boost::math::negative_binomial<%1%>::estimate_upper_bound_on_p";
         RealType result; // of error checks.
         RealType failures = trials - successes;
         if(false == negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, successes, RealType(0), failures, &result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, alpha, &result))
+ function, successes, RealType(0), failures, &result, Policy())
+ && detail::check_probability(function, alpha, &result, Policy()))
         {
           return result;
         }
@@ -198,7 +203,7 @@
         // Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY
         // http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
         //
- return ibetac_inv(successes, failures, alpha);
+ return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(0), Policy());
       } // estimate_upper_bound_on_p
 
       // Estimate number of trials :
@@ -209,14 +214,15 @@
         RealType p, // success fraction 0 <= p <= 1.
         RealType alpha) // risk level threshold 0 <= alpha <= 1.
       {
+ static const char* function = "boost::math::negative_binomial<%1%>::estimate_minimum_number_of_trials";
         // Error checks:
         RealType result;
         if(false == negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, RealType(1), p, k, &result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, alpha, &result))
+ function, RealType(1), p, k, &result, Policy())
+ && detail::check_probability(function, alpha, &result, Policy()))
         { return result; }
 
- result = ibeta_inva(k + 1, p, alpha); // returns n - k
+ result = ibeta_inva(k + 1, p, alpha, Policy()); // returns n - k
         return result + k;
       } // RealType estimate_number_of_failures
 
@@ -225,61 +231,62 @@
         RealType p, // success fraction 0 <= p <= 1.
         RealType alpha) // risk level threshold 0 <= alpha <= 1.
       {
+ static const char* function = "boost::math::negative_binomial<%1%>::estimate_maximum_number_of_trials";
         // Error checks:
         RealType result;
         if(false == negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION, RealType(1), p, k, &result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, alpha, &result))
+ function, RealType(1), p, k, &result, Policy())
+ && detail::check_probability(function, alpha, &result, Policy()))
         { return result; }
 
- result = ibetac_inva(k + 1, p, alpha); // returns n - k
+ result = ibetac_inva(k + 1, p, alpha, Policy()); // returns n - k
         return result + k;
       } // RealType estimate_number_of_trials complemented
 
     private:
       RealType m_r; // successes.
       RealType m_p; // success_fraction
- }; // template <class RealType> class negative_binomial_distribution
+ }; // template <class RealType, class Policy> class negative_binomial_distribution
 
     typedef negative_binomial_distribution<double> negative_binomial; // Reserved name of type double.
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const negative_binomial_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const negative_binomial_distribution<RealType, Policy>& /* dist */)
     { // Range of permissible values for random variable k.
             using boost::math::tools::max_value;
             return std::pair<RealType, RealType>(0, max_value<RealType>()); // max_integer?
     }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const negative_binomial_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const negative_binomial_distribution<RealType, Policy>& /* dist */)
     { // Range of supported values for random variable k.
             // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
             using boost::math::tools::max_value;
             return std::pair<RealType, RealType>(0, max_value<RealType>()); // max_integer?
     }
 
- template <class RealType>
- inline RealType mean(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const negative_binomial_distribution<RealType, Policy>& dist)
     { // Mean of Negative Binomial distribution = r(1-p)/p.
       return dist.successes() * (1 - dist.success_fraction() ) / dist.success_fraction();
     } // mean
 
- //template <class RealType>
- //inline RealType median(const negative_binomial_distribution<RealType>& dist)
+ //template <class RealType, class Policy>
+ //inline RealType median(const negative_binomial_distribution<RealType, Policy>& dist)
     //{ // Median of negative_binomial_distribution is not defined.
- // return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
+ // return policy::raise_domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN());
     //} // median
     // Now implemented via quantile(half) in derived accessors.
 
- template <class RealType>
- inline RealType mode(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const negative_binomial_distribution<RealType, Policy>& dist)
     { // Mode of Negative Binomial distribution = floor[(r-1) * (1 - p)/p]
       using namespace std; // ADL of std functions.
       return floor((dist.successes() -1) * (1 - dist.success_fraction()) / dist.success_fraction());
     } // mode
 
- template <class RealType>
- inline RealType skewness(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const negative_binomial_distribution<RealType, Policy>& dist)
     { // skewness of Negative Binomial distribution = 2-p / (sqrt(r(1-p))
       using namespace std; // ADL of std functions.
       RealType p = dist.success_fraction();
@@ -289,8 +296,8 @@
         sqrt(r * (1 - p));
     } // skewness
 
- template <class RealType>
- inline RealType kurtosis(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const negative_binomial_distribution<RealType, Policy>& dist)
     { // kurtosis of Negative Binomial distribution
       // http://en.wikipedia.org/wiki/Negative_binomial is kurtosis_excess so add 3
       RealType p = dist.success_fraction();
@@ -298,8 +305,8 @@
       return 3 + (6 / r) + ((p * p) / (r * (1 - p)));
     } // kurtosis
 
- template <class RealType>
- inline RealType kurtosis_excess(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const negative_binomial_distribution<RealType, Policy>& dist)
     { // kurtosis excess of Negative Binomial distribution
       // http://mathworld.wolfram.com/Kurtosis.html table of kurtosis_excess
       RealType p = dist.success_fraction();
@@ -307,37 +314,50 @@
       return (6 - p * (6-p)) / (r * (1-p));
     } // kurtosis_excess
 
- template <class RealType>
- inline RealType variance(const negative_binomial_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const negative_binomial_distribution<RealType, Policy>& dist)
     { // Variance of Binomial distribution = r (1-p) / p^2.
       return dist.successes() * (1 - dist.success_fraction())
         / (dist.success_fraction() * dist.success_fraction());
     } // variance
 
- // RealType standard_deviation(const negative_binomial_distribution<RealType>& dist)
+ // RealType standard_deviation(const negative_binomial_distribution<RealType, Policy>& dist)
     // standard_deviation provided by derived accessors.
- // RealType hazard(const negative_binomial_distribution<RealType>& dist)
+ // RealType hazard(const negative_binomial_distribution<RealType, Policy>& dist)
     // hazard of Negative Binomial distribution provided by derived accessors.
- // RealType chf(const negative_binomial_distribution<RealType>& dist)
+ // RealType chf(const negative_binomial_distribution<RealType, Policy>& dist)
     // chf of Negative Binomial distribution provided by derived accessors.
 
- template <class RealType>
- inline RealType pdf(const negative_binomial_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ inline RealType pdf(const negative_binomial_distribution<RealType, Policy>& dist, const RealType k)
     { // Probability Density/Mass Function.
       BOOST_FPU_EXCEPTION_GUARD
 
+ static const char* function = "boost::math::pdf(const negative_binomial_distribution<%1%>&, %1%)";
+
       RealType r = dist.successes();
       RealType p = dist.success_fraction();
+ RealType result;
+ if(false == negative_binomial_detail::check_dist_and_k(
+ function,
+ r,
+ dist.success_fraction(),
+ k,
+ &result, Policy()))
+ {
+ return result;
+ }
 
- RealType result = (p/(r + k)) * ibeta_derivative(r, static_cast<RealType>(k+1), p);
+ result = (p/(r + k)) * ibeta_derivative(r, static_cast<RealType>(k+1), p, Policy());
       // Equivalent to:
       // return exp(lgamma(r + k) - lgamma(r) - lgamma(k+1)) * pow(p, r) * pow((1-p), k);
       return result;
     } // negative_binomial_pdf
 
- template <class RealType>
- inline RealType cdf(const negative_binomial_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ inline RealType cdf(const negative_binomial_distribution<RealType, Policy>& dist, const RealType k)
     { // Cumulative Distribution Function of Negative Binomial.
+ static const char* function = "boost::math::cdf(const negative_binomial_distribution<%1%>&, %1%)";
       using boost::math::ibeta; // Regularized incomplete beta function.
       // k argument may be integral, signed, or unsigned, or floating point.
       // If necessary, it has already been promoted from an integral type.
@@ -346,39 +366,40 @@
       // Error check:
       RealType result;
       if(false == negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ function,
         r,
         dist.success_fraction(),
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
 
- RealType probability = ibeta(r, static_cast<RealType>(k+1), p);
+ RealType probability = ibeta(r, static_cast<RealType>(k+1), p, Policy());
       // Ip(r, k+1) = ibeta(r, k+1, p)
       return probability;
     } // cdf Cumulative Distribution Function Negative Binomial.
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<negative_binomial_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<negative_binomial_distribution<RealType, Policy>, RealType>& c)
       { // Complemented Cumulative Distribution Function Negative Binomial.
 
+ static const char* function = "boost::math::cdf(const negative_binomial_distribution<%1%>&, %1%)";
       using boost::math::ibetac; // Regularized incomplete beta function complement.
       // k argument may be integral, signed, or unsigned, or floating point.
       // If necessary, it has already been promoted from an integral type.
       RealType const& k = c.param;
- negative_binomial_distribution<RealType> const& dist = c.dist;
+ negative_binomial_distribution<RealType, Policy> const& dist = c.dist;
       RealType p = dist.success_fraction();
       RealType r = dist.successes();
       // Error check:
       RealType result;
       if(false == negative_binomial_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ function,
         r,
         p,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -387,14 +408,14 @@
       // 1-p if p is very small, perhaps smaller than machine epsilon.
       // Ip(k+1, r) = ibetac(r, k+1, p)
       // constrain_probability here?
- RealType probability = ibetac(r, static_cast<RealType>(k+1), p);
+ RealType probability = ibetac(r, static_cast<RealType>(k+1), p, Policy());
       // Numerical errors might cause probability to be slightly outside the range < 0 or > 1.
       // This might cause trouble downstream, so warn, possibly throw exception, but constrain to the limits.
       return probability;
     } // cdf Cumulative Distribution Function Negative Binomial.
 
- template <class RealType>
- inline RealType quantile(const negative_binomial_distribution<RealType>& dist, const RealType& P)
+ template <class RealType, class Policy>
+ inline RealType quantile(const negative_binomial_distribution<RealType, Policy>& dist, const RealType& P)
     { // Quantile, percentile/100 or Percent Point Negative Binomial function.
       // Return the number of expected failures k for a given probability p.
 
@@ -402,6 +423,7 @@
       // MAthCAD pnbinom return smallest k such that negative_binomial(k, n, p) >= probability.
       // k argument may be integral, signed, or unsigned, or floating point.
       // BUT Cephes/CodeCogs says: finds argument p (0 to 1) such that cdf(k, n, p) = y
+ static const char* function = "boost::math::quantile(const negative_binomial_distribution<%1%>&, %1%)";
       using namespace std; // ADL of std functions.
 
       RealType p = dist.success_fraction();
@@ -409,7 +431,7 @@
       // Check dist and P.
       RealType result;
       if(false == negative_binomial_detail::check_dist_and_prob
- (BOOST_CURRENT_FUNCTION, r, p, P, &result))
+ (function, r, p, P, &result, Policy()))
       {
         return result;
       }
@@ -417,9 +439,9 @@
       // Special cases.
       if (P == 1)
       { // Would need +infinity failures for total confidence.
- result = tools::overflow_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "Probability argument is 1, which implies infinite failures !");
+ result = policy::raise_overflow_error<RealType>(
+ function,
+ "Probability argument is 1, which implies infinite failures !", Policy());
         return result;
        // usually means return +std::numeric_limits<RealType>::infinity();
        // unless #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR
@@ -432,56 +454,118 @@
       { // p <= pdf(dist, 0) == cdf(dist, 0)
                            return 0;
       }
+ /*
       // Calculate quantile of negative_binomial using the inverse incomplete beta function.
       using boost::math::ibeta_invb;
- return ibeta_invb(r, p, P) - 1; //
+ return ibeta_invb(r, p, P, Policy()) - 1; //
+ */
+ RealType guess = 0;
+ RealType factor = 5;
+ if(r * r * r * P * p > 0.005)
+ guess = detail::inverse_negative_binomial_cornish_fisher(r, p, 1-p, P, 1-P, Policy());
+
+ if(guess < 10)
+ {
+ //
+ // Cornish-Fisher Negative binomial approximation not accurate in this area:
+ //
+ guess = (std::min)(r * 2, RealType(10));
+ }
+ else
+ factor = (1-P < sqrt(tools::epsilon<RealType>())) ? 2 : (guess < 20 ? 1.2f : 1.1f);
+ BOOST_MATH_INSTRUMENT_CODE("guess = " << guess);
+ //
+ // Max iterations permitted:
+ //
+ boost::uintmax_t max_iter = 200;
+ typedef typename Policy::discrete_quantile_type discrete_type;
+ return detail::inverse_discrete_quantile(
+ dist,
+ P,
+ 1-P,
+ guess,
+ factor,
+ RealType(1),
+ discrete_type(),
+ max_iter);
     } // RealType quantile(const negative_binomial_distribution dist, p)
 
- template <class RealType>
- inline RealType quantile(const complemented2_type<negative_binomial_distribution<RealType>, RealType>& c)
- { // Quantile or Percent Point Binomial function.
- // Return the number of expected failures k for a given
- // complement of the probability Q = 1 - P.
-
- // Error checks:
- RealType Q = c.param;
- const negative_binomial_distribution<RealType>& dist = c.dist;
- RealType p = dist.success_fraction();
- RealType r = dist.successes();
- RealType result;
- if(false == negative_binomial_detail::check_dist_and_prob(
- BOOST_CURRENT_FUNCTION,
- r,
- p,
- Q,
- &result))
- {
- return result;
- }
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<negative_binomial_distribution<RealType, Policy>, RealType>& c)
+ { // Quantile or Percent Point Binomial function.
+ // Return the number of expected failures k for a given
+ // complement of the probability Q = 1 - P.
+ static const char* function = "boost::math::quantile(const negative_binomial_distribution<%1%>&, %1%)";
+ using namespace std;
+
+ // Error checks:
+ RealType Q = c.param;
+ const negative_binomial_distribution<RealType, Policy>& dist = c.dist;
+ RealType p = dist.success_fraction();
+ RealType r = dist.successes();
+ RealType result;
+ if(false == negative_binomial_detail::check_dist_and_prob(
+ function,
+ r,
+ p,
+ Q,
+ &result, Policy()))
+ {
+ return result;
+ }
 
- // Special cases:
- //
- if(Q == 1)
- { // There may actually be no answer to this question,
- // since the probability of zero failures may be non-zero,
- return 0; // but zero is the best we can do:
- }
- if (-Q <= powm1(dist.success_fraction(), dist.successes()))
- { // q <= cdf(complement(dist, 0)) == pdf(dist, 0)
- return 0; //
- }
- if(Q == 0)
- { // Probability 1 - Q == 1 so infinite failures to achieve certainty.
- // Would need +infinity failures for total confidence.
- result = tools::overflow_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "Probability argument complement is 0, which implies infinite failures !");
- return result;
- // usually means return +std::numeric_limits<RealType>::infinity();
- // unless #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR
- }
- return ibetac_invb(r, p, Q) -1;
- } // quantile complement
+ // Special cases:
+ //
+ if(Q == 1)
+ { // There may actually be no answer to this question,
+ // since the probability of zero failures may be non-zero,
+ return 0; // but zero is the best we can do:
+ }
+ if (-Q <= powm1(dist.success_fraction(), dist.successes(), Policy()))
+ { // q <= cdf(complement(dist, 0)) == pdf(dist, 0)
+ return 0; //
+ }
+ if(Q == 0)
+ { // Probability 1 - Q == 1 so infinite failures to achieve certainty.
+ // Would need +infinity failures for total confidence.
+ result = policy::raise_overflow_error<RealType>(
+ function,
+ "Probability argument complement is 0, which implies infinite failures !", Policy());
+ return result;
+ // usually means return +std::numeric_limits<RealType>::infinity();
+ // unless #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR
+ }
+ //return ibetac_invb(r, p, Q, Policy()) -1;
+ RealType guess = 0;
+ RealType factor = 5;
+ if(r * r * r * (1-Q) * p > 0.005)
+ guess = detail::inverse_negative_binomial_cornish_fisher(r, p, 1-p, 1-Q, Q, Policy());
+
+ if(guess < 10)
+ {
+ //
+ // Cornish-Fisher Negative binomial approximation not accurate in this area:
+ //
+ guess = (std::min)(r * 2, RealType(10));
+ }
+ else
+ factor = (Q < sqrt(tools::epsilon<RealType>())) ? 2 : (guess < 20 ? 1.2f : 1.1f);
+ BOOST_MATH_INSTRUMENT_CODE("guess = " << guess);
+ //
+ // Max iterations permitted:
+ //
+ boost::uintmax_t max_iter = 200;
+ typedef typename Policy::discrete_quantile_type discrete_type;
+ return detail::inverse_discrete_quantile(
+ dist,
+ 1-Q,
+ Q,
+ guess,
+ factor,
+ RealType(1),
+ discrete_type(),
+ max_iter);
+ } // quantile complement
 
  } // namespace math
 } // namespace boost

Modified: sandbox/math_toolkit/boost/math/distributions/normal.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/normal.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/normal.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,18 +13,20 @@
 // From MathWorld--A Wolfram Web Resource.
 // http://mathworld.wolfram.com/NormalDistribution.html
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/erf.hpp> // for erf/erfc.
 #include <boost/math/distributions/complement.hpp>
 
 #include <utility>
 
-namespace boost{ namespace math
-{
-template <class RealType = double>
+namespace boost{ namespace math{
+
+template <class RealType = double, class Policy = policy::policy<> >
 class normal_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    normal_distribution(RealType mean = 0, RealType sd = 1)
       : m_mean(mean), m_sd(sd) {}
@@ -48,23 +50,23 @@
 
 typedef normal_distribution<double> normal;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const normal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const normal_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity.
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const normal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const normal_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity.
 }
 
-template <class RealType>
-inline RealType pdf(const normal_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
@@ -81,8 +83,8 @@
    return result;
 }
 
-template <class RealType>
-inline RealType cdf(const normal_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const normal_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
@@ -92,12 +94,12 @@
    RealType diff = (x - mean) / (sd * constants::root_two<RealType>());
    RealType result;
 
- result = boost::math::erfc(-diff) / 2;
+ result = boost::math::erfc(-diff, Policy()) / 2;
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const normal_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const normal_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
@@ -106,7 +108,7 @@
 
    RealType r;
 
- r = boost::math::erfc_inv(2 * p);
+ r = boost::math::erfc_inv(2 * p, Policy());
    r = -r;
    r *= sd * constants::root_two<RealType>();
    r += mean;
@@ -114,8 +116,8 @@
    return r;
 }
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<normal_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
@@ -126,13 +128,13 @@
    RealType diff = (x - mean) / (sd * constants::root_two<RealType>());
    RealType result;
 
- result = boost::math::erfc(diff) / 2;
+ result = boost::math::erfc(diff, Policy()) / 2;
 
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<normal_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
@@ -141,50 +143,50 @@
    RealType q = c.param;
 
    RealType r;
- r = boost::math::erfc_inv(2 * q);
+ r = boost::math::erfc_inv(2 * q, Policy());
    r *= sd * constants::root_two<RealType>();
    r += mean;
    return r;
 }
 
-template <class RealType>
-inline RealType mean(const normal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const normal_distribution<RealType, Policy>& dist)
 {
    return dist.mean();
 }
 
-template <class RealType>
-inline RealType standard_deviation(const normal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType standard_deviation(const normal_distribution<RealType, Policy>& dist)
 {
    return dist.standard_deviation();
 }
 
-template <class RealType>
-inline RealType mode(const normal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const normal_distribution<RealType, Policy>& dist)
 {
    return dist.mean();
 }
 
-template <class RealType>
-inline RealType median(const normal_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const normal_distribution<RealType, Policy>& dist)
 {
    return dist.mean();
 }
 
-template <class RealType>
-inline RealType skewness(const normal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType skewness(const normal_distribution<RealType, Policy>& /*dist*/)
 {
    return 0;
 }
 
-template <class RealType>
-inline RealType kurtosis(const normal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis(const normal_distribution<RealType, Policy>& /*dist*/)
 {
    return 3;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const normal_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const normal_distribution<RealType, Policy>& /*dist*/)
 {
    return 0;
 }

Modified: sandbox/math_toolkit/boost/math/distributions/pareto.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/pareto.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/pareto.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -14,6 +14,7 @@
 // From MathWorld--A Wolfram Web Resource.
 // http://mathworld.wolfram.com/ParetoDistribution.html
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/distributions/complement.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/special_functions/powm1.hpp>
@@ -26,11 +27,11 @@
   {
     namespace detail
     { // Parameter checking.
- template <class RealType>
+ template <class RealType, class Policy>
       inline bool check_pareto_location(
         const char* function,
         RealType location,
- RealType* result)
+ RealType* result, const Policy& pol)
       {
         if((boost::math::isfinite)(location))
         { // any > 0 finite value is OK.
@@ -40,26 +41,26 @@
           }
           else
           {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
               function,
- "Location parameter is %1%, but must be > 0!", location);
+ "Location parameter is %1%, but must be > 0!", location, pol);
             return false;
           }
         }
         else
         { // Not finite.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Location parameter is %1%, but must be finite!", location);
+ "Location parameter is %1%, but must be finite!", location, pol);
           return false;
         }
       } // bool check_pareto_location
 
- template <class RealType>
+ template <class RealType, class Policy>
       inline bool check_pareto_shape(
         const char* function,
         RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
       {
         if((boost::math::isfinite)(shape))
         { // Any finite value is OK.
@@ -69,26 +70,26 @@
           }
           else
           {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
               function,
- "Shape parameter is %1%, but must be > 0!", shape);
+ "Shape parameter is %1%, but must be > 0!", shape, pol);
             return false;
           }
         }
         else
         { // Not finite.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Shape parameter is %1%, but must be finite!", shape);
+ "Shape parameter is %1%, but must be finite!", shape, pol);
           return false;
         }
       } // bool check_pareto_shape(
 
- template <class RealType>
+ template <class RealType, class Policy>
       inline bool check_pareto_x(
         const char* function,
         RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
       {
         if((boost::math::isfinite)(x))
         { //
@@ -98,52 +99,46 @@
           }
           else
           {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
               function,
- "x parameter is %1%, but must be > 0 !", x);
+ "x parameter is %1%, but must be > 0 !", x, pol);
             return false;
           }
         }
         else
         { // Not finite..
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "x parameter is %1%, but must be finite!", x);
+ "x parameter is %1%, but must be finite!", x, pol);
           return false;
         }
       } // bool check_pareto_x
 
- template <class RealType>
+ template <class RealType, class Policy>
       inline bool check_pareto( // distribution parameters.
         const char* function,
         RealType location,
         RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
       {
- if(check_pareto_location(function, location, result)
- && check_pareto_shape(function, shape, result) )
- {
- return true;
- }
- else
- {
- return false;
- }
+ return check_pareto_location(function, location, result, pol)
+ && check_pareto_shape(function, shape, result, pol);
       } // bool check_pareto(
 
     } // namespace detail
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class pareto_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       pareto_distribution(RealType location = 1, RealType shape = 1)
         : m_location(location), m_shape(shape)
       { // Constructor.
         RealType result;
- detail::check_pareto(BOOST_CURRENT_FUNCTION, location, shape, &result);
+ detail::check_pareto("boost::math::pareto_distribution<%1%>::pareto_distribution", location, shape, &result, Policy());
       }
 
       RealType location()const
@@ -163,66 +158,77 @@
 
     typedef pareto_distribution<double> pareto; // Convenience to allow pareto(2., 3.);
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const pareto_distribution<RealType>& /*dist*/)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const pareto_distribution<RealType, Policy>& /*dist*/)
     { // Range of permissible values for random variable x.
       using boost::math::tools::max_value;
       return std::pair<RealType, RealType>(0, max_value<RealType>()); // location zero to + infinity.
     } // range
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const pareto_distribution<RealType, Policy>& dist)
     { // Range of supported values for random variable x.
       // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
       using boost::math::tools::max_value;
       return std::pair<RealType, RealType>(dist.location(), max_value<RealType>() ); // location to + infinity.
     } // support
 
- template <class RealType>
- inline RealType pdf(const pareto_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ inline RealType pdf(const pareto_distribution<RealType, Policy>& dist, const RealType& x)
     {
       using namespace std; // for ADL of std function pow.
+ static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)";
       RealType location = dist.location();
+ RealType shape = dist.shape();
       RealType result;
- detail::check_pareto_x(BOOST_CURRENT_FUNCTION, x, &result);
+ if(false == (detail::check_pareto_x(function, x, &result, Policy())
+ && detail::check_pareto(function, location, shape, &result, Policy())))
+ return result;
       if (x < location)
       { // regardless of shape, pdf is zero.
         return 0;
       }
- RealType shape = dist.shape();
 
       result = shape * pow(location, shape) / pow(x, shape+1);
       return result;
     } // pdf
 
- template <class RealType>
- inline RealType cdf(const pareto_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ inline RealType cdf(const pareto_distribution<RealType, Policy>& dist, const RealType& x)
     {
       using namespace std; // for ADL of std function pow.
+ static const char* function = "boost::math::cdf(const pareto_distribution<%1%>&, %1%)";
       RealType location = dist.location();
+ RealType shape = dist.shape();
       RealType result;
- detail::check_pareto_x(BOOST_CURRENT_FUNCTION, x, &result);
+
+ if(false == (detail::check_pareto_x(function, x, &result, Policy())
+ && detail::check_pareto(function, location, shape, &result, Policy())))
+ return result;
+
       if (x <= location)
       { // regardless of shape, cdf is zero.
         return 0;
       }
 
- RealType shape = dist.shape();
       // result = RealType(1) - pow((location / x), shape);
- result = -powm1(location/x, shape); // should be more accurate.
+ result = -powm1(location/x, shape, Policy()); // should be more accurate.
       return result;
     } // cdf
 
- template <class RealType>
- inline RealType quantile(const pareto_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ inline RealType quantile(const pareto_distribution<RealType, Policy>& dist, const RealType& p)
     {
       using namespace std; // for ADL of std function pow.
+ static const char* function = "boost::math::quantile(const pareto_distribution<%1%>&, %1%)";
       RealType result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ RealType location = dist.location();
+ RealType shape = dist.shape();
+ if(false == (detail::check_probability(function, p, &result, Policy())
+ && detail::check_pareto(function, location, shape, &result, Policy())))
       {
         return result;
       }
- RealType location = dist.location();
       if (p == 0)
       {
         return location; // x must be location (or less).
@@ -231,45 +237,48 @@
       {
         return tools::max_value<RealType>(); // x = + infinity.
       }
- RealType shape = dist.shape();
       result = location /
         (pow((1 - p), 1 / shape));
       // K. Krishnamoorthy, ISBN 1-58488-635-8 eq 23.1.3
       return result;
     } // quantile
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<pareto_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<pareto_distribution<RealType, Policy>, RealType>& c)
     {
        using namespace std; // for ADL of std function pow.
+ static const char* function = "boost::math::cdf(const pareto_distribution<%1%>&, %1%)";
        RealType result;
        RealType x = c.param;
- if(false == detail::check_pareto_x(BOOST_CURRENT_FUNCTION, x, &result))
- {
- return result;
- }
        RealType location = c.dist.location();
+ RealType shape = c.dist.shape();
+ if(false == (detail::check_pareto_x(function, x, &result, Policy())
+ && detail::check_pareto(function, location, shape, &result, Policy())))
+ return result;
+
        if (x <= location)
        { // regardless of shape, cdf is zero, and complement is unity.
          return 1;
        }
- RealType shape = c.dist.shape();
        result = pow((location/x), shape);
    
        return result;
     } // cdf complement
     
- template <class RealType>
- inline RealType quantile(const complemented2_type<pareto_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<pareto_distribution<RealType, Policy>, RealType>& c)
     {
       using namespace std; // for ADL of std function pow.
+ static const char* function = "boost::math::quantile(const pareto_distribution<%1%>&, %1%)";
       RealType result;
       RealType q = c.param;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ RealType location = c.dist.location();
+ RealType shape = c.dist.shape();
+ if(false == (detail::check_probability(function, q, &result, Policy())
+ && detail::check_pareto(function, location, shape, &result, Policy())))
       {
         return result;
       }
- RealType location = c.dist.location();
       if (q == 1)
       {
         return location; // x must be location (or less).
@@ -278,15 +287,20 @@
       {
         return tools::max_value<RealType>(); // x = + infinity.
       }
- RealType shape = c.dist.shape();
       result = location / (pow(q, 1 / shape));
       // K. Krishnamoorthy, ISBN 1-58488-635-8 eq 23.1.3
       return result;
     } // quantile complement
 
- template <class RealType>
- inline RealType mean(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const pareto_distribution<RealType, Policy>& dist)
     {
+ RealType result;
+ static const char* function = "boost::math::mean(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, dist.location(), dist.shape(), &result, Policy()))
+ {
+ return result;
+ }
       if (dist.shape() > RealType(1))
       {
         return dist.shape() * dist.location() / (dist.shape() - 1);
@@ -298,25 +312,36 @@
       }
     } // mean
 
- template <class RealType>
- inline RealType mode(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const pareto_distribution<RealType, Policy>& dist)
     {
       return dist.location();
     } // mode
 
- template <class RealType>
- inline RealType median(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType median(const pareto_distribution<RealType, Policy>& dist)
     {
+ RealType result;
+ static const char* function = "boost::math::median(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, dist.location(), dist.shape(), &result, Policy()))
+ {
+ return result;
+ }
       using namespace std;
- return dist.location() * pow(2, (1/dist.shape()));
+ return dist.location() * pow(RealType(2), (1/dist.shape()));
     } // median
 
- template <class RealType>
- inline RealType variance(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const pareto_distribution<RealType, Policy>& dist)
     {
       RealType result;
       RealType location = dist.location();
       RealType shape = dist.shape();
+ static const char* function = "boost::math::variance(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, location, shape, &result, Policy()))
+ {
+ return result;
+ }
       if (shape > 2)
       {
         result = (location * location * shape) /
@@ -324,19 +349,24 @@
       }
       else
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "variance is undefined for shape <= 2, but got %1%.", dist.shape());
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "variance is undefined for shape <= 2, but got %1%.", dist.shape(), Policy());
       }
       return result;
     } // variance
 
- template <class RealType>
- inline RealType skewness(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const pareto_distribution<RealType, Policy>& dist)
     {
       using namespace std;
       RealType result;
       RealType shape = dist.shape();
+ static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, dist.location(), shape, &result, Policy()))
+ {
+ return result;
+ }
       if (shape > 3)
       {
         result = sqrt((shape - 2) / shape) *
@@ -345,18 +375,23 @@
       }
       else
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "skewness is undefined for shape <= 3, but got %1%.", dist.shape());
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "skewness is undefined for shape <= 3, but got %1%.", dist.shape(), Policy());
       }
       return result;
     } // skewness
 
- template <class RealType>
- inline RealType kurtosis(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const pareto_distribution<RealType, Policy>& dist)
     {
       RealType result;
       RealType shape = dist.shape();
+ static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, dist.location(), shape, &result, Policy()))
+ {
+ return result;
+ }
       if (shape > 4)
       {
         result = 3 * ((shape - 2) * (3 * shape * shape + shape + 2)) /
@@ -364,18 +399,23 @@
       }
       else
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "kurtosis_excess is undefined for shape <= 4, but got %1%.", shape);
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "kurtosis_excess is undefined for shape <= 4, but got %1%.", shape, Policy());
       }
       return result;
     } // kurtosis
 
- template <class RealType>
- inline RealType kurtosis_excess(const pareto_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const pareto_distribution<RealType, Policy>& dist)
     {
       RealType result;
       RealType shape = dist.shape();
+ static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)";
+ if(false == detail::check_pareto(function, dist.location(), shape, &result, Policy()))
+ {
+ return result;
+ }
       if (shape > 4)
       {
         result = 6 * ((shape * shape * shape) + (shape * shape) - 6 * shape - 2) /
@@ -383,9 +423,9 @@
       }
       else
       {
- result = tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
- "kurtosis_excess is undefined for shape <= 4, but got %1%.", dist.shape());
+ result = policy::raise_domain_error<RealType>(
+ function,
+ "kurtosis_excess is undefined for shape <= 4, but got %1%.", dist.shape(), Policy());
       }
       return result;
     } // kurtosis_excess

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -36,12 +36,14 @@
 #ifndef BOOST_MATH_SPECIAL_POISSON_HPP
 #define BOOST_MATH_SPECIAL_POISSON_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/gamma.hpp> // for incomplete gamma. gamma_q
 #include <boost/math/distributions/complement.hpp> // complements
 #include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
 #include <boost/math/special_functions/fpclassify.hpp> // isnan.
 #include <boost/math/special_functions/factorials.hpp> // factorials.
 #include <boost/math/tools/roots.hpp> // for root finding.
+#include <boost/math/distributions/detail/inv_discrete_quantile.hpp>
 
 #include <utility>
 
@@ -56,86 +58,148 @@
 {
   namespace math
   {
+ namespace detail{
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::integer_nearest>&,
+ boost::uintmax_t& max_iter);
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::integer_above>&,
+ boost::uintmax_t& max_iter);
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::integer_below>&,
+ boost::uintmax_t& max_iter);
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::integer_outside>&,
+ boost::uintmax_t& max_iter);
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::integer_inside>&,
+ boost::uintmax_t& max_iter);
+ template <class Dist>
+ inline typename Dist::value_type
+ inverse_discrete_quantile(
+ const Dist& dist,
+ const typename Dist::value_type& p,
+ const typename Dist::value_type& guess,
+ const typename Dist::value_type& multiplier,
+ const typename Dist::value_type& adder,
+ const policy::discrete_quantile<policy::real>&,
+ boost::uintmax_t& max_iter);
+ }
     namespace poisson_detail
     {
       // Common error checking routines for Poisson distribution functions.
       // These are convoluted, & apparently redundant, to try to ensure that
       // checks are always performed, even if exceptions are not enabled.
 
- template <class RealType>
- inline bool check_mean(const char* function, const RealType& mean, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol)
       {
         if(!(boost::math::isfinite)(mean) || (mean < 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Mean argument is %1%, but must be >= 0 !", mean);
+ "Mean argument is %1%, but must be >= 0 !", mean, pol);
           return false;
         }
         return true;
       } // bool check_mean
 
- template <class RealType>
- inline bool check_mean_NZ(const char* function, const RealType& mean, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_mean_NZ(const char* function, const RealType& mean, RealType* result, const Policy& pol)
       { // mean == 0 is considered an error.
         if( !(boost::math::isfinite)(mean) || (mean <= 0))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Mean argument is %1%, but must be > 0 !", mean);
+ "Mean argument is %1%, but must be > 0 !", mean, pol);
           return false;
         }
         return true;
       } // bool check_mean_NZ
 
- template <class RealType>
- inline bool check_dist(const char* function, const RealType& mean, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& mean, RealType* result, const Policy& pol)
       { // Only one check, so this is redundant really but should be optimized away.
- return check_mean_NZ(function, mean, result);
+ return check_mean_NZ(function, mean, result, pol);
       } // bool check_dist
 
- template <class RealType>
- inline bool check_k(const char* function, const RealType& k, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_k(const char* function, const RealType& k, RealType* result, const Policy& pol)
       {
         if((k < 0) || !(boost::math::isfinite)(k))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Number of events k argument is %1%, but must be >= 0 !", k);
+ "Number of events k argument is %1%, but must be >= 0 !", k, pol);
           return false;
         }
         return true;
       } // bool check_k
 
- template <class RealType>
- inline bool check_dist_and_k(const char* function, RealType mean, RealType k, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_k(const char* function, RealType mean, RealType k, RealType* result, const Policy& pol)
       {
- if((check_dist(function, mean, result) == false) ||
- (check_k(function, k, result) == false))
+ if((check_dist(function, mean, result, pol) == false) ||
+ (check_k(function, k, result, pol) == false))
         {
           return false;
         }
         return true;
       } // bool check_dist_and_k
 
- template <class RealType>
- inline bool check_prob(const char* function, const RealType& p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
       { // Check 0 <= p <= 1
         if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "Probability argument is %1%, but must be >= 0 and <= 1 !", p);
+ "Probability argument is %1%, but must be >= 0 and <= 1 !", p, pol);
           return false;
         }
         return true;
       } // bool check_prob
 
- template <class RealType>
- inline bool check_dist_and_prob(const char* function, RealType mean, RealType p, RealType* result)
+ template <class RealType, class Policy>
+ inline bool check_dist_and_prob(const char* function, RealType mean, RealType p, RealType* result, const Policy& pol)
       {
- if((check_dist(function, mean, result) == false) ||
- (check_prob(function, p, result) == false))
+ if((check_dist(function, mean, result, pol) == false) ||
+ (check_prob(function, p, result, pol) == false))
         {
           return false;
         }
@@ -144,19 +208,20 @@
 
     } // namespace poisson_detail
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
     class poisson_distribution
     {
     public:
       typedef RealType value_type;
+ typedef Policy policy_type;
 
       poisson_distribution(RealType mean = 1) : m_l(mean) // mean (lambda).
       { // Expected mean number of events that occur during the given interval.
         RealType r;
         poisson_detail::check_dist(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::poisson_distribution<%1%>::poisson_distribution",
           m_l,
- &r);
+ &r, Policy());
       } // poisson_distribution constructor.
 
       RealType mean() const
@@ -170,42 +235,42 @@
     private:
       // Data member, initialized by constructor.
       RealType m_l; // mean number of occurrences.
- }; // template <class RealType> class poisson_distribution
+ }; // template <class RealType, class Policy> class poisson_distribution
 
     typedef poisson_distribution<double> poisson; // Reserved name of type double.
 
     // Non-member functions to give properties of the distribution.
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const poisson_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const poisson_distribution<RealType, Policy>& /* dist */)
     { // Range of permissible values for random variable k.
             using boost::math::tools::max_value;
             return std::pair<RealType, RealType>(0, max_value<RealType>()); // Max integer?
     }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const poisson_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const poisson_distribution<RealType, Policy>& /* dist */)
     { // Range of supported values for random variable k.
             // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
             using boost::math::tools::max_value;
             return std::pair<RealType, RealType>(0, max_value<RealType>());
     }
 
- template <class RealType>
- inline RealType mean(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const poisson_distribution<RealType, Policy>& dist)
     { // Mean of poisson distribution = lambda.
       return dist.mean();
     } // mean
 
- template <class RealType>
- inline RealType mode(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const poisson_distribution<RealType, Policy>& dist)
     { // mode.
       using namespace std; // ADL of std functions.
       return floor(dist.mean());
     }
 
- //template <class RealType>
- //inline RealType median(const poisson_distribution<RealType>& dist)
+ //template <class RealType, class Policy>
+ //inline RealType median(const poisson_distribution<RealType, Policy>& dist)
     //{ // median = approximately lambda + 1/3 - 0.2/lambda
     // RealType l = dist.mean();
     // return dist.mean() + static_cast<RealType>(0.3333333333333333333333333333333333333333333333)
@@ -214,24 +279,24 @@
     // Query posted on Wikipedia.
     // Now implemented via quantile(half) in derived accessors.
 
- template <class RealType>
- inline RealType variance(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const poisson_distribution<RealType, Policy>& dist)
     { // variance.
       return dist.mean();
     }
 
- // RealType standard_deviation(const poisson_distribution<RealType>& dist)
+ // RealType standard_deviation(const poisson_distribution<RealType, Policy>& dist)
     // standard_deviation provided by derived accessors.
 
- template <class RealType>
- inline RealType skewness(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const poisson_distribution<RealType, Policy>& dist)
     { // skewness = sqrt(l).
       using namespace std; // ADL of std functions.
       return 1 / sqrt(dist.mean());
     }
 
- template <class RealType>
- inline RealType kurtosis_excess(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const poisson_distribution<RealType, Policy>& dist)
     { // skewness = sqrt(l).
       return 1 / dist.mean(); // kurtosis_excess 1/mean from Wiki & MathWorld eq 31.
       // http://mathworld.wolfram.com/Kurtosis.html explains that the kurtosis excess
@@ -239,8 +304,8 @@
       // whereas the true kurtosis is 3.
     } // RealType kurtosis_excess
 
- template <class RealType>
- inline RealType kurtosis(const poisson_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const poisson_distribution<RealType, Policy>& dist)
     { // kurtosis is 4th moment about the mean = u4 / sd ^ 4
       // http://en.wikipedia.org/wiki/Curtosis
       // kurtosis can range from -2 (flat top) to +infinity (sharp peak & heavy tails).
@@ -251,23 +316,22 @@
       // whereas the true kurtosis is 3.
     } // RealType kurtosis
 
- template <class RealType>
- RealType pdf(const poisson_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ RealType pdf(const poisson_distribution<RealType, Policy>& dist, const RealType k)
     { // Probability Density/Mass Function.
       // Probability that there are EXACTLY k occurrences (or arrivals).
       BOOST_FPU_EXCEPTION_GUARD
 
- using boost::math::tools::domain_error;
       using namespace std; // for ADL of std functions.
 
       RealType mean = dist.mean();
       // Error check:
       RealType result;
       if(false == poisson_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::pdf(const poisson_distribution<%1%>&, %1%)",
         mean,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -294,13 +358,13 @@
         // (e ^ -mean * mean ^ k) / k!
         // == exp(log(e ^ -mean) + log (mean ^ k) - lgamma(k+1))
         // exp( -mean + log(mean) * k - lgamma(k+1))
- return exp(-mean + log(mean) * k - boost::math::lgamma(k+1));
+ return exp(-mean + log(mean) * k - boost::math::lgamma(k+1, Policy()));
         // return gamma_p_derivative(k+1, mean); // equivalent & also passes tests.
       }
     } // pdf
 
- template <class RealType>
- RealType cdf(const poisson_distribution<RealType>& dist, const RealType k)
+ template <class RealType, class Policy>
+ RealType cdf(const poisson_distribution<RealType, Policy>& dist, const RealType k)
     { // Cumulative Distribution Function Poisson.
       // The random variate k is the number of occurrences(or arrivals)
       // k argument may be integral, signed, or unsigned, or floating point.
@@ -325,10 +389,10 @@
       // Error checks:
       RealType result;
       if(false == poisson_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(const poisson_distribution<%1%>&, %1%)",
         mean,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -347,11 +411,11 @@
       // it's cheaper than the gamma function.
       // BUT this is now done efficiently by gamma_q function.
       // Calculate poisson cdf using the gamma_q function.
- return gamma_q(k+1, mean);
+ return gamma_q(k+1, mean, Policy());
     } // binomial cdf
 
- template <class RealType>
- RealType cdf(const complemented2_type<poisson_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ RealType cdf(const complemented2_type<poisson_distribution<RealType, Policy>, RealType>& c)
     { // Complemented Cumulative Distribution Function Poisson
       // The random variate k is the number of events, occurrences or arrivals.
       // k argument may be integral, signed, or unsigned, or floating point.
@@ -370,17 +434,17 @@
       // instead the incomplete gamma integral is employed,
 
       RealType const& k = c.param;
- poisson_distribution<RealType> const& dist = c.dist;
+ poisson_distribution<RealType, Policy> const& dist = c.dist;
 
       RealType mean = dist.mean();
 
       // Error checks:
       RealType result;
       if(false == poisson_detail::check_dist_and_k(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::cdf(const poisson_distribution<%1%>&, %1%)",
         mean,
         k,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -391,24 +455,24 @@
       }
       if (k == 0)
       { // Avoid repeated checks on k and mean in gamma_p.
- return -boost::math::expm1(-mean);
+ return -boost::math::expm1(-mean, Policy());
       }
       // Unlike un-complemented cdf (sum from 0 to k),
       // can't use finite sum from k+1 to infinity for small integral k,
       // anyway it is now done efficiently by gamma_p.
- return gamma_p(k + 1, mean); // Calculate Poisson cdf using the gamma_p function.
+ return gamma_p(k + 1, mean, Policy()); // Calculate Poisson cdf using the gamma_p function.
       // CCDF = gamma_p(k+1, lambda)
     } // poisson ccdf
 
- template <class RealType>
- inline RealType quantile(const poisson_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ inline RealType quantile(const poisson_distribution<RealType, Policy>& dist, const RealType& p)
     { // Quantile (or Percent Point) Poisson function.
       // Return the number of expected events k for a given probability p.
       RealType result; // of Argument checks:
       if(false == poisson_detail::check_prob(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(const poisson_distribution<%1%>&, %1%)",
         p,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -416,13 +480,14 @@
       if (dist.mean() == 0)
       { // if mean = 0 then p = 0, so k can be anything?
          if (false == poisson_detail::check_mean_NZ(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(const poisson_distribution<%1%>&, %1%)",
          dist.mean(),
- &result))
+ &result, Policy()))
         {
           return result;
         }
       }
+ /*
       using namespace std; // ADL of std functions.
       // if(p == 0) NOT necessarily zero!
       // Not necessarily any special value of k because is unlimited.
@@ -430,23 +495,55 @@
                         { // if p <= cdf for 0 events (== pdf for 0 events), then quantile must be zero.
                                 return 0;
                         }
- return gamma_q_inva(dist.mean(), p) - 1;
+ return gamma_q_inva(dist.mean(), p, Policy()) - 1;
+ */
+ typedef typename Policy::discrete_quantile_type discrete_type;
+ boost::uintmax_t max_iter = 200;
+ RealType guess, factor = 8;
+ RealType z = dist.mean();
+ if(z < 1)
+ guess = z;
+ else
+ guess = boost::math::detail::inverse_poisson_cornish_fisher(z, p, 1-p, Policy());
+ if(z > 5)
+ {
+ if(z > 1000)
+ factor = 1.01f;
+ else if(z > 50)
+ factor = 1.1f;
+ else if(guess > 10)
+ factor = 1.25f;
+ else
+ factor = 2;
+ if(guess < 1.1)
+ factor = 8;
+ }
+
+ return detail::inverse_discrete_quantile(
+ dist,
+ p,
+ 1-p,
+ guess,
+ factor,
+ RealType(1),
+ discrete_type(),
+ max_iter);
    } // quantile
 
- template <class RealType>
- inline RealType quantile(const complemented2_type<poisson_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<poisson_distribution<RealType, Policy>, RealType>& c)
     { // Quantile (or Percent Point) of Poisson function.
       // Return the number of expected events k for a given
       // complement of the probability q.
       //
       // Error checks:
       RealType q = c.param;
- const poisson_distribution<RealType>& dist = c.dist;
+ const poisson_distribution<RealType, Policy>& dist = c.dist;
       RealType result; // of argument checks.
       if(false == poisson_detail::check_prob(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(const poisson_distribution<%1%>&, %1%)",
         q,
- &result))
+ &result, Policy()))
       {
         return result;
       }
@@ -454,18 +551,51 @@
       if (dist.mean() == 0)
       { // if mean = 0 then p = 0, so k can be anything?
          if (false == poisson_detail::check_mean_NZ(
- BOOST_CURRENT_FUNCTION,
+ "boost::math::quantile(const poisson_distribution<%1%>&, %1%)",
          dist.mean(),
- &result))
+ &result, Policy()))
         {
           return result;
         }
       }
+ /*
       if (-q <= boost::math::expm1(-dist.mean()))
                         { // if q <= cdf(complement for 0 events, then quantile must be zero.
                                 return 0;
                         }
- return gamma_p_inva(dist.mean(), q) -1;
+ return gamma_p_inva(dist.mean(), q, Policy()) -1;
+ */
+ typedef typename Policy::discrete_quantile_type discrete_type;
+ boost::uintmax_t max_iter = 200;
+ RealType guess, factor = 8;
+ RealType z = dist.mean();
+ if(z < 1)
+ guess = z;
+ else
+ guess = boost::math::detail::inverse_poisson_cornish_fisher(z, 1-q, q, Policy());
+ if(z > 5)
+ {
+ if(z > 1000)
+ factor = 1.01f;
+ else if(z > 50)
+ factor = 1.1f;
+ else if(guess > 10)
+ factor = 1.25f;
+ else
+ factor = 2;
+ if(guess < 1.1)
+ factor = 8;
+ }
+
+ return detail::inverse_discrete_quantile(
+ dist,
+ 1-q,
+ q,
+ guess,
+ factor,
+ RealType(1),
+ discrete_type(),
+ max_iter);
    } // quantile complement.
 
   } // namespace math
@@ -479,6 +609,7 @@
 // for this distribution have been defined, in order to
 // keep compilers that support two-phase lookup happy.
 #include <boost/math/distributions/detail/derived_accessors.hpp>
+#include <boost/math/distributions/detail/inv_discrete_quantile.hpp>
 
 #endif // BOOST_MATH_SPECIAL_POISSON_HPP
 

Modified: sandbox/math_toolkit/boost/math/distributions/rayleigh.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/rayleigh.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/rayleigh.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -6,6 +6,7 @@
 #ifndef BOOST_STATS_rayleigh_HPP
 #define BOOST_STATS_rayleigh_HPP
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/special_functions/expm1.hpp>
@@ -24,44 +25,45 @@
 
 namespace detail
 { // Error checks:
- template <class RealType>
- inline bool verify_sigma(const char* function, RealType sigma, RealType* presult)
+ template <class RealType, class Policy>
+ inline bool verify_sigma(const char* function, RealType sigma, RealType* presult, const Policy& pol)
   {
      if(sigma <= 0)
      {
- *presult = tools::domain_error<RealType>(
+ *presult = policy::raise_domain_error<RealType>(
            function,
- "The scale parameter \"sigma\" must be > 0, but was: %1%.", sigma);
+ "The scale parameter \"sigma\" must be > 0, but was: %1%.", sigma, pol);
         return false;
      }
      return true;
   } // bool verify_sigma
 
- template <class RealType>
- inline bool verify_rayleigh_x(const char* function, RealType x, RealType* presult)
+ template <class RealType, class Policy>
+ inline bool verify_rayleigh_x(const char* function, RealType x, RealType* presult, const Policy& pol)
   {
      if(x < 0)
      {
- *presult = tools::domain_error<RealType>(
+ *presult = policy::raise_domain_error<RealType>(
            function,
- "The random variable must be >= 0, but was: %1%.", x);
+ "The random variable must be >= 0, but was: %1%.", x, pol);
         return false;
      }
      return true;
   } // bool verify_rayleigh_x
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class rayleigh_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    rayleigh_distribution(RealType sigma = 1)
       : m_sigma(sigma)
    {
       RealType err;
- detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &err);
+ detail::verify_sigma("boost::math::rayleigh_distribution<%1%>::rayleigh_distribution", sigma, &err, Policy());
    } // rayleigh_distribution
 
    RealType sigma()const
@@ -75,33 +77,34 @@
 
 typedef rayleigh_distribution<double> rayleigh;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const rayleigh_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const rayleigh_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(static_cast<RealType>(1), max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const rayleigh_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const rayleigh_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>((1), max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const rayleigh_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const rayleigh_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std function exp.
 
    RealType sigma = dist.sigma();
    RealType result;
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::pdf(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
- if(false == detail::verify_rayleigh_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::verify_rayleigh_x(function, x, &result, Policy()))
    {
       return result;
    }
@@ -110,35 +113,37 @@
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const rayleigh_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const rayleigh_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
    RealType result;
    RealType sigma = dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::cdf(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
- if(false == detail::verify_rayleigh_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::verify_rayleigh_x(function, x, &result, Policy()))
    {
       return result;
    }
- result = -boost::math::expm1(-x * x / ( 2 * sigma * sigma));
+ result = -boost::math::expm1(-x * x / ( 2 * sigma * sigma), Policy());
    return result;
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const rayleigh_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const rayleigh_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
    RealType result;
    RealType sigma = dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::quantile(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
       return result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(false == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 0)
@@ -147,25 +152,26 @@
    }
    if(p == 1)
    {
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
    }
- result = sqrt(-2 * sigma * sigma * boost::math::log1p(-p));
+ result = sqrt(-2 * sigma * sigma * boost::math::log1p(-p, Policy()));
    return result;
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<rayleigh_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<rayleigh_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
    RealType result;
    RealType sigma = c.dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::cdf(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
    RealType x = c.param;
- if(false == detail::verify_rayleigh_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::verify_rayleigh_x(function, x, &result, Policy()))
    {
       return result;
    }
@@ -173,19 +179,20 @@
    return result;
 } // cdf complement
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<rayleigh_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<rayleigh_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions, log & sqrt.
 
    RealType result;
    RealType sigma = c.dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::quantile(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
    RealType q = c.param;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(false == detail::check_probability(function, q, &result, Policy()))
    {
       return result;
    }
@@ -195,18 +202,19 @@
    }
    if(q == 0)
    {
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
    }
    result = sqrt(-2 * sigma * sigma * log(q));
    return result;
 } // quantile complement
 
-template <class RealType>
-inline RealType mean(const rayleigh_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const rayleigh_distribution<RealType, Policy>& dist)
 {
    RealType result;
    RealType sigma = dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::mean(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
@@ -214,12 +222,13 @@
    return sigma * root_half_pi<RealType>();
 } // mean
 
-template <class RealType>
-inline RealType variance(const rayleigh_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const rayleigh_distribution<RealType, Policy>& dist)
 {
    RealType result;
    RealType sigma = dist.sigma();
- if(false == detail::verify_sigma(BOOST_CURRENT_FUNCTION, sigma, &result))
+ static const char* function = "boost::math::variance(const rayleigh_distribution<%1%>&, %1%)";
+ if(false == detail::verify_sigma(function, sigma, &result, Policy()))
    {
       return result;
    }
@@ -227,21 +236,21 @@
    return four_minus_pi<RealType>() * sigma * sigma / 2;
 } // variance
 
-template <class RealType>
-inline RealType mode(const rayleigh_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const rayleigh_distribution<RealType, Policy>& dist)
 {
    return dist.sigma();
 }
 
-template <class RealType>
-inline RealType median(const rayleigh_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const rayleigh_distribution<RealType, Policy>& dist)
 {
    using boost::math::constants::root_ln_four;
    return root_ln_four<RealType>() * dist.sigma();
 }
 
-template <class RealType>
-inline RealType skewness(const rayleigh_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType skewness(const rayleigh_distribution<RealType, Policy>& /*dist*/)
 {
   // using namespace boost::math::constants;
   return static_cast<RealType>(0.63111065781893713819189935154422777984404221106391L);
@@ -249,8 +258,8 @@
   // return 2 * root_pi<RealType>() * pi_minus_three<RealType>() / pow23_four_minus_pi<RealType>();
 }
 
-template <class RealType>
-inline RealType kurtosis(const rayleigh_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis(const rayleigh_distribution<RealType, Policy>& /*dist*/)
 {
   // using namespace boost::math::constants;
   return static_cast<RealType>(3.2450893006876380628486604106197544154170667057995L);
@@ -259,8 +268,8 @@
   // (four_minus_pi<RealType>() * four_minus_pi<RealType>());
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const rayleigh_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const rayleigh_distribution<RealType, Policy>& /*dist*/)
 {
   //using namespace boost::math::constants;
   // Computed using NTL at 150 bit, about 50 decimal digits.

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 // http://en.wikipedia.org/wiki/Student%27s_t_distribution
 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda3664.htm
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/beta.hpp> // for ibeta(a, b, x).
 #include <boost/math/distributions/complement.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
@@ -23,17 +24,18 @@
 
 namespace boost{ namespace math{
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class students_t_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    students_t_distribution(RealType i) : m_df(i)
    { // Constructor.
       RealType result;
       detail::check_df(
- BOOST_CURRENT_FUNCTION, m_df, &result);
+ "boost::math::students_t_distribution<%1%>::students_t_distribution", m_df, &result, Policy());
    } // students_t_distribution
 
    RealType degrees_of_freedom()const
@@ -58,23 +60,23 @@
 
 typedef students_t_distribution<double> students_t;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const students_t_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const students_t_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const students_t_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const students_t_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const students_t_distribution<RealType>& dist, const RealType& t)
+template <class RealType, class Policy>
+inline RealType pdf(const students_t_distribution<RealType, Policy>& dist, const RealType& t)
 {
    BOOST_FPU_EXCEPTION_GUARD
    using namespace std; // for ADL of std functions
@@ -83,31 +85,31 @@
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result))
+ "boost::math::pdf(const students_t_distribution<%1%>&, %1%)", degrees_of_freedom, &error_result, Policy()))
       return error_result;
    // Might conceivably permit df = +infinity and use normal distribution.
    RealType result;
    RealType basem1 = t * t / degrees_of_freedom;
    if(basem1 < 0.125)
    {
- result = exp(-boost::math::log1p(basem1) * (1+degrees_of_freedom) / 2);
+ result = exp(-boost::math::log1p(basem1, Policy()) * (1+degrees_of_freedom) / 2);
    }
    else
    {
       result = pow(1 / (1 + basem1), (degrees_of_freedom + 1) / 2);
    }
- result /= sqrt(degrees_of_freedom) * boost::math::beta(degrees_of_freedom / 2, RealType(0.5f));
+ result /= sqrt(degrees_of_freedom) * boost::math::beta(degrees_of_freedom / 2, RealType(0.5f), Policy());
    return result;
 } // pdf
 
-template <class RealType>
-inline RealType cdf(const students_t_distribution<RealType>& dist, const RealType& t)
+template <class RealType, class Policy>
+inline RealType cdf(const students_t_distribution<RealType, Policy>& dist, const RealType& t)
 {
    RealType degrees_of_freedom = dist.degrees_of_freedom();
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result))
+ "boost::math::cdf(const students_t_distribution<%1%>&, %1%)", degrees_of_freedom, &error_result, Policy()))
       return error_result;
 
    if (t == 0)
@@ -137,31 +139,18 @@
    if(degrees_of_freedom > 2 * t2)
    {
       RealType z = t2 / (degrees_of_freedom + t2);
- probability = ibetac(static_cast<RealType>(0.5), degrees_of_freedom / 2, z) / 2;
+ probability = ibetac(static_cast<RealType>(0.5), degrees_of_freedom / 2, z, Policy()) / 2;
    }
    else
    {
       RealType z = degrees_of_freedom / (degrees_of_freedom + t2);
- probability = ibeta(degrees_of_freedom / 2, static_cast<RealType>(0.5), z) / 2;
- }
- // Check 0 <= probability probability <= 1.
- // Numerical errors might cause probability to be slightly outside the range < 0 or > 1.
- // This might cause trouble downstream, so warn, possibly throw exception, but constrain to the limits.
- if (probability < static_cast<RealType>(0.))
- {
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "probability %1% is < 0, so has been constrained to zero !", probability);
- return static_cast<RealType>(0.); // Constrain to zero if logic_error does not throw.
- }
- if(probability > static_cast<RealType>(1.))
- {
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "probability %1% is > 1, so has been constrained to unity!", probability);
- return static_cast<RealType>(1.); // Constrain to unity if logic_error does not throw.
+ probability = ibeta(degrees_of_freedom / 2, static_cast<RealType>(0.5), z, Policy()) / 2;
    }
    return (t > 0 ? 1 - probability : probability);
 } // cdf
 
-template <class RealType>
-inline RealType quantile(const students_t_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const students_t_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
    //
@@ -172,17 +161,18 @@
    //
    // Check for domain errors:
    //
+ static const char* function = "boost::math::quantile(const students_t_distribution<%1%>&, %1%)";
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, degrees_of_freedom, &error_result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, probability, &error_result))
+ function, degrees_of_freedom, &error_result, Policy())
+ && detail::check_probability(function, probability, &error_result, Policy()))
       return error_result;
 
    // Special cases, regardless of degrees_of_freedom.
    if (probability == 0)
- return -tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<RealType>(function, 0, Policy());
    if (probability == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
    if (probability == static_cast<RealType>(0.5))
      return 0;
    //
@@ -197,7 +187,7 @@
    RealType t, x, y;
    x = ibeta_inv(degrees_of_freedom / 2, RealType(0.5), 2 * probability, &y);
    if(degrees_of_freedom * y > tools::max_value<RealType>() * x)
- t = tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ t = tools::overflow_error<RealType>(function);
    else
       t = sqrt(degrees_of_freedom * y / x);
    //
@@ -215,17 +205,17 @@
    // and a couple of epsilon at double precision and in the central
    // region where most use cases will occur...
    //
- return boost::math::detail::fast_students_t_quantile(degrees_of_freedom, probability);
+ return boost::math::detail::fast_students_t_quantile(degrees_of_freedom, probability, Policy());
 } // quantile
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<students_t_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<students_t_distribution<RealType, Policy>, RealType>& c)
 {
    return cdf(c.dist, -c.param);
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<students_t_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<students_t_distribution<RealType, Policy>, RealType>& c)
 {
    return -quantile(c.dist, c.param);
 }
@@ -237,7 +227,7 @@
 //
 // Functors for finding degrees of freedom:
 //
-template <class RealType>
+template <class RealType, class Policy>
 struct sample_size_func
 {
    sample_size_func(RealType a, RealType b, RealType s, RealType d)
@@ -247,7 +237,7 @@
    {
       if(df <= tools::min_value<RealType>())
          return 1;
- students_t_distribution<RealType> t(df);
+ students_t_distribution<RealType, Policy> t(df);
       RealType qa = quantile(complement(t, alpha));
       RealType qb = quantile(complement(t, beta));
       qa += qb;
@@ -261,109 +251,110 @@
 
 } // namespace detail
 
-template <class RealType>
-RealType students_t_distribution<RealType>::estimate_degrees_of_freedom(
+template <class RealType, class Policy>
+RealType students_t_distribution<RealType, Policy>::estimate_degrees_of_freedom(
       RealType difference_from_mean,
       RealType alpha,
       RealType beta,
       RealType sd,
       RealType hint)
 {
+ static const char* function = "boost::math::students_t_distribution<%1%>::estimate_degrees_of_freedom";
    //
    // Check for domain errors:
    //
    RealType error_result;
    if(false == detail::check_probability(
- BOOST_CURRENT_FUNCTION, alpha, &error_result)
- && detail::check_probability(BOOST_CURRENT_FUNCTION, beta, &error_result))
+ function, alpha, &error_result, Policy())
+ && detail::check_probability(function, beta, &error_result, Policy()))
       return error_result;
 
    if(hint <= 0)
       hint = 1;
 
- detail::sample_size_func<RealType> f(alpha, beta, sd, difference_from_mean);
- tools::eps_tolerance<RealType> tol(tools::digits<RealType>());
+ detail::sample_size_func<RealType, Policy> f(alpha, beta, sd, difference_from_mean);
+ tools::eps_tolerance<RealType> tol(policy::digits<RealType, Policy>());
    boost::uintmax_t max_iter = 10000;
- std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter);
+ 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)
    {
- tools::logic_error<RealType>(BOOST_CURRENT_FUNCTION, "Unable to locate solution in a reasonable time:"
+ policy::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"
- " or the answer is infinite. Current best guess is %1%", result);
+ " or the answer is infinite. Current best guess is %1%", result, Policy());
    }
    return result;
 }
 
-template <class RealType>
-inline RealType mean(const students_t_distribution<RealType>& )
+template <class RealType, class Policy>
+inline RealType mean(const students_t_distribution<RealType, Policy>& )
 {
    return 0;
 }
 
-template <class RealType>
-inline RealType variance(const students_t_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const students_t_distribution<RealType, Policy>& dist)
 {
    // Error check:
    RealType error_result;
    if(false == detail::check_df(
- BOOST_CURRENT_FUNCTION, dist.degrees_of_freedom(), &error_result))
+ "boost::math::variance(students_t_distribution<%1%> const&, %1%)", dist.degrees_of_freedom(), &error_result, Policy()))
       return error_result;
 
    RealType v = dist.degrees_of_freedom();
    return v / (v - 2);
 }
 
-template <class RealType>
-inline RealType mode(const students_t_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType mode(const students_t_distribution<RealType, Policy>& /*dist*/)
 {
    return 0;
 }
 
-template <class RealType>
-inline RealType median(const students_t_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline RealType median(const students_t_distribution<RealType, Policy>& /*dist*/)
 {
    return 0;
 }
 
-template <class RealType>
-inline RealType skewness(const students_t_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const students_t_distribution<RealType, Policy>& dist)
 {
    if(dist.degrees_of_freedom() <= 3)
    {
- tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ policy::raise_domain_error<RealType>(
+ "boost::math::skewness(students_t_distribution<%1%> const&, %1%)",
          "Skewness is undefined for degrees of freedom <= 3, but got %1%.",
- dist.degrees_of_freedom());
+ dist.degrees_of_freedom(), Policy());
    }
    return 0;
 }
 
-template <class RealType>
-inline RealType kurtosis(const students_t_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const students_t_distribution<RealType, Policy>& dist)
 {
    RealType df = dist.degrees_of_freedom();
    if(df <= 3)
    {
- tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ policy::raise_domain_error<RealType>(
+ "boost::math::kurtosis(students_t_distribution<%1%> const&, %1%)",
          "Skewness is undefined for degrees of freedom <= 3, but got %1%.",
- df);
+ df, Policy());
    }
    return 3 * (df - 2) / (df - 4);
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const students_t_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const students_t_distribution<RealType, Policy>& dist)
 {
    // see http://mathworld.wolfram.com/Kurtosis.html
    RealType df = dist.degrees_of_freedom();
    if(df <= 3)
    {
- tools::domain_error<RealType>(
- BOOST_CURRENT_FUNCTION,
+ policy::raise_domain_error<RealType>(
+ "boost::math::kurtosis_excess(students_t_distribution<%1%> const&, %1%)",
          "Skewness is undefined for degrees of freedom <= 3, but got %1%.",
- df);
+ df, Policy());
    }
    return 6 / (df - 4);
 }

Modified: sandbox/math_toolkit/boost/math/distributions/triangular.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/triangular.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/triangular.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 // http://mathworld.wolfram.com/TriangularDistribution.html
 // http://en.wikipedia.org/wiki/Triangular_distribution
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/expm1.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/distributions/complement.hpp>
@@ -21,11 +22,11 @@
 {
   namespace detail
   {
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_triangular_lower(
       const char* function,
       RealType lower,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(lower))
       { // Any finite value is OK.
@@ -33,18 +34,18 @@
       }
       else
       { // Not finite: infinity or NaN.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "Lower parameter is %1%, but must be finite!", lower);
+ "Lower parameter is %1%, but must be finite!", lower, pol);
         return false;
       }
     } // bool check_triangular_lower(
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_triangular_mode(
       const char* function,
       RealType mode,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(mode))
       { // any finite value is OK.
@@ -52,18 +53,18 @@
       }
       else
       { // Not finite: infinity or NaN.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "Mode parameter is %1%, but must be finite!", mode);
+ "Mode parameter is %1%, but must be finite!", mode, pol);
         return false;
       }
     } // bool check_triangular_mode(
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_triangular_upper(
       const char* function,
       RealType upper,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(upper))
       { // any finite value is OK.
@@ -71,18 +72,18 @@
       }
       else
       { // Not finite: infinity or NaN.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "Upper parameter is %1%, but must be finite!", upper);
+ "Upper parameter is %1%, but must be finite!", upper, pol);
         return false;
       }
     } // bool check_triangular_upper(
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_triangular_x(
       const char* function,
       RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(x))
       { // Any finite value is OK
@@ -90,58 +91,59 @@
       }
       else
       { // Not finite: infinity or NaN.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "x parameter is %1%, but must be finite!", x);
+ "x parameter is %1%, but must be finite!", x, pol);
         return false;
       }
     } // bool check_triangular_x
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_triangular(
       const char* function,
       RealType lower,
       RealType mode,
       RealType upper,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
- if(check_triangular_lower(function, lower, result)
- && check_triangular_mode(function, mode, result)
- && check_triangular_upper(function, upper, result)
+ if(check_triangular_lower(function, lower, result, pol)
+ && check_triangular_mode(function, mode, result, pol)
+ && check_triangular_upper(function, upper, result, pol)
         && (lower < upper) // lower == upper NOT useful.
         )
       {
         if (mode < lower)
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "mode parameter is %1%, but must be >= than lower!", lower);
+ "mode parameter is %1%, but must be >= than lower!", lower, pol);
           return false;
         }
         if (mode > upper )
         {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
             function,
- "mode parameter is %1%, but must be <= than upper!", upper);
+ "mode parameter is %1%, but must be <= than upper!", upper, pol);
           return false;
         }
         return true;
       }
       else
       { // upper and lower have each been checked before, so must be lower >= upper.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "lower parameter is %1%, but must be less than upper!", lower);
+ "lower parameter is %1%, but must be less than upper!", lower, pol);
         return false;
       }
     } // bool check_triangular
   } // namespace detail
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
   class triangular_distribution
   {
   public:
     typedef RealType value_type;
+ typedef Policy policy_type;
 
     triangular_distribution(RealType lower = -1, RealType mode = 0, RealType upper = 1)
       : m_lower(lower), m_mode(mode), m_upper(upper) // Constructor.
@@ -150,7 +152,7 @@
       // But this is more useful in most applications to approximate normal distribution,
       // where the central value is the most likely and deviations either side equally likely.
       RealType result;
- detail::check_triangular(BOOST_CURRENT_FUNCTION,lower, mode, upper, &result);
+ detail::check_triangular("boost::math::triangular_distribution<%1%>::triangular_distribution",lower, mode, upper, &result, Policy());
     }
     // Accessor functions.
     RealType lower()const
@@ -174,32 +176,33 @@
 
   typedef triangular_distribution<double> triangular;
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const triangular_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const triangular_distribution<RealType, Policy>& /* dist */)
   { // Range of permissible values for random variable x.
     using boost::math::tools::max_value;
     return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
   }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const triangular_distribution<RealType, Policy>& dist)
   { // Range of supported values for random variable x.
     // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
     return std::pair<RealType, RealType>(dist.lower(), dist.upper());
   }
 
- template <class RealType>
- RealType pdf(const triangular_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ RealType pdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x)
   {
+ static const char* function = "boost::math::pdf(const triangular_distribution<%1%>&, %1%)";
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, lower, mode, upper, &result))
+ if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_triangular_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_triangular_x(function, x, &result, Policy()))
     {
       return result;
     }
@@ -223,20 +226,21 @@
     { // (x > mode)
       return 2 * (upper - x) / ((upper - lower) * (upper - mode));
     }
- } // RealType pdf(const triangular_distribution<RealType>& dist, const RealType& x)
+ } // RealType pdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x)
 
- template <class RealType>
- inline RealType cdf(const triangular_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ inline RealType cdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x)
   {
+ static const char* function = "boost::math::cdf(const triangular_distribution<%1%>&, %1%)";
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, lower, mode, upper, &result))
+ if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_triangular_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_triangular_x(function, x, &result, Policy()))
     {
       return result;
     }
@@ -257,21 +261,22 @@
     {
       return 1 - (upper - x) * (upper - x) / ((upper - lower) * (upper - mode));
     }
- } // RealType cdf(const triangular_distribution<RealType>& dist, const RealType& x)
+ } // RealType cdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x)
 
- template <class RealType>
- RealType quantile(const triangular_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ RealType quantile(const triangular_distribution<RealType, Policy>& dist, const RealType& p)
   {
     using namespace std; // for ADL of std functions (sqrt).
+ static const char* function = "boost::math::quantile(const triangular_distribution<%1%>&, %1%)";
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION,lower, mode, upper, &result))
+ if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(false == detail::check_probability(function, p, &result, Policy()))
     {
       return result;
     }
@@ -299,21 +304,22 @@
     }
     return result;
 
- } // RealType quantile(const triangular_distribution<RealType>& dist, const RealType& q)
+ } // RealType quantile(const triangular_distribution<RealType, Policy>& dist, const RealType& q)
 
- template <class RealType>
- RealType cdf(const complemented2_type<triangular_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ RealType cdf(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c)
   {
+ static const char* function = "boost::math::cdf(const triangular_distribution<%1%>&, %1%)";
     RealType lower = c.dist.lower();
     RealType mode = c.dist.mode();
     RealType upper = c.dist.upper();
     RealType x = c.param;
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, lower, mode, upper, &result))
+ if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_triangular_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_triangular_x(function, x, &result, Policy()))
     {
       return result;
     }
@@ -333,22 +339,23 @@
     {
       return (upper - x) * (upper - x) / ((upper - lower) * (upper - mode));
     }
- } // RealType cdf(const complemented2_type<triangular_distribution<RealType>, RealType>& c)
+ } // RealType cdf(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c)
 
- template <class RealType>
- RealType quantile(const complemented2_type<triangular_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ RealType quantile(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c)
   {
     using namespace std; // Aid ADL for sqrt.
+ static const char* function = "boost::math::quantile(const triangular_distribution<%1%>&, %1%)";
     RealType l = c.dist.lower();
     RealType m = c.dist.mode();
     RealType u = c.dist.upper();
     RealType q = c.param; // probability 0 to 1.
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, l, m, u, &result))
+ if(false == detail::check_triangular(function, l, m, u, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(false == detail::check_probability(function, q, &result, Policy()))
     {
       return result;
     }
@@ -381,56 +388,60 @@
       result = upper - sqrt((upper - lower) * (upper - mode) * q);
     }
     return result;
- } // RealType quantile(const complemented2_type<triangular_distribution<RealType>, RealType>& c)
+ } // RealType quantile(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c)
 
- template <class RealType>
- inline RealType mean(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const triangular_distribution<RealType, Policy>& dist)
   {
+ static const char* function = "boost::math::mean(const triangular_distribution<%1%>&)";
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, lower, mode, upper, &result))
+ if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy()))
     {
       return result;
     }
     return (lower + upper + mode) / 3;
- } // RealType mean(const triangular_distribution<RealType>& dist)
+ } // RealType mean(const triangular_distribution<RealType, Policy>& dist)
 
 
- template <class RealType>
- inline RealType variance(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const triangular_distribution<RealType, Policy>& dist)
   {
+ static const char* function = "boost::math::mean(const triangular_distribution<%1%>&)";
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION, lower, mode, upper, &result))
+ if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy()))
     {
       return result;
     }
     return (lower * lower + upper * upper + mode * mode - lower * upper - lower * mode - upper * mode) / 18;
- } // RealType variance(const triangular_distribution<RealType>& dist)
+ } // RealType variance(const triangular_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType mode(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const triangular_distribution<RealType, Policy>& dist)
   {
+ static const char* function = "boost::math::mode(const triangular_distribution<%1%>&)";
     RealType mode = dist.mode();
     RealType result; // of checks.
- if(false == detail::check_triangular_mode(BOOST_CURRENT_FUNCTION, mode, &result))
+ if(false == detail::check_triangular_mode(function, mode, &result, Policy()))
     { // This should never happen!
       return result;
     }
     return mode;
   } // RealType mode
 
- template <class RealType>
- inline RealType median(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType median(const triangular_distribution<RealType, Policy>& dist)
   {
     using namespace std; // ADL of std functions.
+ static const char* function = "boost::math::median(const triangular_distribution<%1%>&)";
     RealType mode = dist.mode();
     RealType result; // of checks.
- if(false == detail::check_triangular_mode(BOOST_CURRENT_FUNCTION, mode, &result))
+ if(false == detail::check_triangular_mode(function, mode, &result, Policy()))
     { // This should never happen!
       return result;
     }
@@ -446,46 +457,49 @@
     }
   } // RealType mode
 
- template <class RealType>
- inline RealType skewness(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const triangular_distribution<RealType, Policy>& dist)
   {
     using namespace std; // for ADL of std functions
     using namespace boost::math::constants; // for root_two
+ static const char* function = "boost::math::skewness(const triangular_distribution<%1%>&)";
 
     RealType lower = dist.lower();
     RealType mode = dist.mode();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION,lower, mode, upper, &result))
+ if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy()))
     {
       return result;
     }
     return root_two<RealType>() * (lower + upper - 2 * mode) * (2 * lower - upper - mode) * (lower - 2 * upper + mode) /
       (5 * pow((lower * lower + upper + upper + mode * mode - lower * upper - lower * mode - upper * mode), RealType(3)/RealType(2)));
- } // RealType skewness(const triangular_distribution<RealType>& dist)
+ } // RealType skewness(const triangular_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType kurtosis(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const triangular_distribution<RealType, Policy>& dist)
   { // These checks may be belt and braces as should have been checked on construction?
+ static const char* function = "boost::math::kurtosis(const triangular_distribution<%1%>&)";
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType mode = dist.mode();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION,lower, mode, upper, &result))
+ if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy()))
     {
       return result;
     }
     return static_cast<RealType>(12)/5; // 12/5 = 2.4;
- } // RealType kurtosis_excess(const triangular_distribution<RealType>& dist)
+ } // RealType kurtosis_excess(const triangular_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType kurtosis_excess(const triangular_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const triangular_distribution<RealType, Policy>& dist)
   { // These checks may be belt and braces as should have been checked on construction?
+ static const char* function = "boost::math::kurtosis_excess(const triangular_distribution<%1%>&)";
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType mode = dist.mode();
     RealType result; // of checks.
- if(false == detail::check_triangular(BOOST_CURRENT_FUNCTION,lower, mode, upper, &result))
+ if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy()))
     {
       return result;
     }

Modified: sandbox/math_toolkit/boost/math/distributions/uniform.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/uniform.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/uniform.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -15,8 +15,7 @@
 // http://documents.wolfram.com/calculationcenter/v2/Functions/ListsMatrices/Statistics/UniformDistribution.html
 // http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
 
-#include <boost/math/special_functions/gamma.hpp>
-#include <boost/math/special_functions/expm1.hpp>
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/distributions/complement.hpp>
 
@@ -26,11 +25,11 @@
 {
   namespace detail
   {
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_uniform_lower(
       const char* function,
       RealType lower,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(lower))
       { // any finite value is OK.
@@ -38,18 +37,18 @@
       }
       else
       { // Not finite.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "Lower parameter is %1%, but must be finite!", lower);
+ "Lower parameter is %1%, but must be finite!", lower, pol);
         return false;
       }
     } // bool check_uniform_lower(
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_uniform_upper(
       const char* function,
       RealType upper,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(upper))
       { // Any finite value is OK.
@@ -57,18 +56,18 @@
       }
       else
       { // Not finite.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "Upper parameter is %1%, but must be finite!", upper);
+ "Upper parameter is %1%, but must be finite!", upper, pol);
         return false;
       }
     } // bool check_uniform_upper(
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_uniform_x(
       const char* function,
       RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
       if((boost::math::isfinite)(x))
       { // Any finite value is OK
@@ -76,48 +75,49 @@
       }
       else
       { // Not finite..
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "x parameter is %1%, but must be finite!", x);
+ "x parameter is %1%, but must be finite!", x, pol);
         return false;
       }
     } // bool check_uniform_x
 
- template <class RealType>
+ template <class RealType, class Policy>
     inline bool check_uniform(
       const char* function,
       RealType lower,
       RealType upper,
- RealType* result)
+ RealType* result, const Policy& pol)
     {
- if(check_uniform_lower(function, lower, result)
- && check_uniform_upper(function, upper, result)
+ if(check_uniform_lower(function, lower, result, pol)
+ && check_uniform_upper(function, upper, result, pol)
         && (lower < upper)) // If lower == upper then 1 / (upper-lower) = 1/0 = +infinity!
       {
         return true;
       }
       else
       { // upper and lower have been checked before, so must be lower >= upper.
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
           function,
- "lower parameter is %1%, but must be less than upper!", lower);
+ "lower parameter is %1%, but must be less than upper!", lower, pol);
         return false;
       }
     } // bool check_uniform(
 
   } // namespace detail
 
- template <class RealType = double>
+ template <class RealType = double, class Policy = policy::policy<> >
   class uniform_distribution
   {
   public:
     typedef RealType value_type;
+ typedef Policy policy_type;
 
     uniform_distribution(RealType lower = 0, RealType upper = 1) // Constructor.
       : m_lower(lower), m_upper(upper) // Default is standard uniform distribution.
     {
       RealType result;
- detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result);
+ detail::check_uniform("boost::math::uniform_distribution<%1%>::uniform_distribution", lower, upper, &result, Policy());
     }
     // Accessor functions.
     RealType lower()const
@@ -137,32 +137,32 @@
 
   typedef uniform_distribution<double> uniform;
 
- template <class RealType>
- inline const std::pair<RealType, RealType> range(const uniform_distribution<RealType>& /* dist */)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const uniform_distribution<RealType, Policy>& /* dist */)
   { // Range of permissible values for random variable x.
           using boost::math::tools::max_value;
           return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity
   }
 
- template <class RealType>
- inline const std::pair<RealType, RealType> support(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const uniform_distribution<RealType, Policy>& dist)
   { // Range of supported values for random variable x.
           // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
           using boost::math::tools::max_value;
           return std::pair<RealType, RealType>(dist.lower(), dist.upper());
   }
 
- template <class RealType>
- inline RealType pdf(const uniform_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ inline RealType pdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::pdf(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_uniform_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_uniform_x("boost::math::pdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy()))
     {
       return result;
     }
@@ -175,19 +175,19 @@
     {
       return 1 / (upper - lower);
     }
- } // RealType pdf(const uniform_distribution<RealType>& dist, const RealType& x)
+ } // RealType pdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x)
 
- template <class RealType>
- inline RealType cdf(const uniform_distribution<RealType>& dist, const RealType& x)
+ template <class RealType, class Policy>
+ inline RealType cdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION,lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::cdf(const uniform_distribution<%1%>&, %1%)",lower, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_uniform_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_uniform_x("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy()))
     {
       return result;
     }
@@ -200,19 +200,19 @@
       return 1;
     }
     return (x - lower) / (upper - lower); // lower <= x <= upper
- } // RealType cdf(const uniform_distribution<RealType>& dist, const RealType& x)
+ } // RealType cdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x)
 
- template <class RealType>
- inline RealType quantile(const uniform_distribution<RealType>& dist, const RealType& p)
+ template <class RealType, class Policy>
+ inline RealType quantile(const uniform_distribution<RealType, Policy>& dist, const RealType& p)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION,lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::quantile(const uniform_distribution<%1%>&, %1%)",lower, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(false == detail::check_probability("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", p, &result, Policy()))
     {
       return result;
     }
@@ -225,20 +225,20 @@
       return upper;
     }
     return p * (upper - lower) + lower;
- } // RealType quantile(const uniform_distribution<RealType>& dist, const RealType& p)
+ } // RealType quantile(const uniform_distribution<RealType, Policy>& dist, const RealType& p)
 
- template <class RealType>
- inline RealType cdf(const complemented2_type<uniform_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType cdf(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c)
   {
     RealType lower = c.dist.lower();
     RealType upper = c.dist.upper();
     RealType x = c.param;
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_uniform_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_uniform_x("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy()))
     {
       return result;
     }
@@ -251,20 +251,20 @@
       return 1;
     }
     return (upper - x) / (upper - lower);
- } // RealType cdf(const complemented2_type<uniform_distribution<RealType>, RealType>& c)
+ } // RealType cdf(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c)
 
- template <class RealType>
- inline RealType quantile(const complemented2_type<uniform_distribution<RealType>, RealType>& c)
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c)
   {
     RealType lower = c.dist.lower();
     RealType upper = c.dist.upper();
     RealType q = c.param;
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy()))
     {
       return result;
     }
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(false == detail::check_probability("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", q, &result, Policy()))
       if(q == 0)
       {
         return lower;
@@ -274,42 +274,42 @@
         return upper;
       }
       return -q * (upper - lower) + upper;
- } // RealType quantile(const complemented2_type<uniform_distribution<RealType>, RealType>& c)
+ } // RealType quantile(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c)
 
- template <class RealType>
- inline RealType mean(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mean(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::mean(const uniform_distribution<%1%>&)", lower, upper, &result, Policy()))
     {
       return result;
     }
     return (lower + upper ) / 2;
- } // RealType mean(const uniform_distribution<RealType>& dist)
+ } // RealType mean(const uniform_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType variance(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType variance(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::variance(const uniform_distribution<%1%>&)", lower, upper, &result, Policy()))
     {
       return result;
     }
     return (upper - lower) * ( upper - lower) / 12;
     // for standard uniform = 0.833333333333333333333333333333333333333333;
- } // RealType variance(const uniform_distribution<RealType>& dist)
+ } // RealType variance(const uniform_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType mode(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType mode(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::mode(const uniform_distribution<%1%>&)", lower, upper, &result, Policy()))
     {
       return result;
     }
@@ -317,46 +317,46 @@
     return result;
   }
 
- template <class RealType>
- inline RealType median(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType median(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::median(const uniform_distribution<%1%>&)", lower, upper, &result, Policy()))
     {
       return result;
     }
     return (lower + upper) / 2; //
   }
- template <class RealType>
- inline RealType skewness(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType skewness(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION,lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::skewness(const uniform_distribution<%1%>&)",lower, upper, &result, Policy()))
     {
       return result;
     }
     return 0;
- } // RealType skewness(const uniform_distribution<RealType>& dist)
+ } // RealType skewness(const uniform_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType kurtosis_excess(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis_excess(const uniform_distribution<RealType, Policy>& dist)
   {
     RealType lower = dist.lower();
     RealType upper = dist.upper();
     RealType result; // of checks.
- if(false == detail::check_uniform(BOOST_CURRENT_FUNCTION, lower, upper, &result))
+ if(false == detail::check_uniform("boost::math::kurtosis_execess(const uniform_distribution<%1%>&)", lower, upper, &result, Policy()))
     {
       return result;
     }
     return static_cast<RealType>(-6)/5; // -6/5 = -1.2;
- } // RealType kurtosis_excess(const uniform_distribution<RealType>& dist)
+ } // RealType kurtosis_excess(const uniform_distribution<RealType, Policy>& dist)
 
- template <class RealType>
- inline RealType kurtosis(const uniform_distribution<RealType>& dist)
+ template <class RealType, class Policy>
+ inline RealType kurtosis(const uniform_distribution<RealType, Policy>& dist)
   {
     return kurtosis_excess(dist) + 3;
   }

Modified: sandbox/math_toolkit/boost/math/distributions/weibull.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/weibull.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/weibull.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,9 @@
 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda3668.htm
 // http://mathworld.wolfram.com/WeibullDistribution.html
 
+#include <boost/math/distributions/fwd.hpp>
 #include <boost/math/special_functions/gamma.hpp>
+#include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/special_functions/expm1.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/distributions/complement.hpp>
@@ -20,61 +22,62 @@
 {
 namespace detail{
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_weibull_shape(
       const char* function,
       RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
    if((shape < 0) || !(boost::math::isfinite)(shape))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Shape parameter is %1%, but must be > 0 !", shape);
+ "Shape parameter is %1%, but must be > 0 !", shape, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_weibull_x(
       const char* function,
       RealType const& x,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
    if((x < 0) || !(boost::math::isfinite)(x))
    {
- *result = tools::domain_error<RealType>(
+ *result = policy::raise_domain_error<RealType>(
          function,
- "Random variate is %1% but must be >= 0 !", x);
+ "Random variate is %1% but must be >= 0 !", x, pol);
       return false;
    }
    return true;
 }
 
-template <class RealType>
+template <class RealType, class Policy>
 inline bool check_weibull(
       const char* function,
       RealType scale,
       RealType shape,
- RealType* result)
+ RealType* result, const Policy& pol)
 {
- return check_scale(function, scale, result) && check_weibull_shape(function, shape, result);
+ return check_scale(function, scale, result, pol) && check_weibull_shape(function, shape, result, pol);
 }
 
 } // namespace detail
 
-template <class RealType = double>
+template <class RealType = double, class Policy = policy::policy<> >
 class weibull_distribution
 {
 public:
    typedef RealType value_type;
+ typedef Policy policy_type;
 
    weibull_distribution(RealType shape, RealType scale = 1)
       : m_shape(shape), m_scale(scale)
    {
       RealType result;
- detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result);
+ detail::check_weibull("boost::math::weibull_distribution<%1%>::weibull_distribution", scale, shape, &result, Policy());
    }
 
    RealType shape()const
@@ -96,33 +99,35 @@
 
 typedef weibull_distribution<double> weibull;
 
-template <class RealType>
-inline const std::pair<RealType, RealType> range(const weibull_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> range(const weibull_distribution<RealType, Policy>& /*dist*/)
 { // Range of permissible values for random variable x.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline const std::pair<RealType, RealType> support(const weibull_distribution<RealType>& /*dist*/)
+template <class RealType, class Policy>
+inline const std::pair<RealType, RealType> support(const weibull_distribution<RealType, Policy>& /*dist*/)
 { // Range of supported values for random variable x.
         // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(0, max_value<RealType>());
 }
 
-template <class RealType>
-inline RealType pdf(const weibull_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType pdf(const weibull_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::pdf(const weibull_distribution<%1%>, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_weibull_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_weibull_x(function, x, &result, Policy()))
       return result;
 
    if(x == 0)
@@ -134,59 +139,65 @@
    return result;
 }
 
-template <class RealType>
-inline RealType cdf(const weibull_distribution<RealType>& dist, const RealType& x)
+template <class RealType, class Policy>
+inline RealType cdf(const weibull_distribution<RealType, Policy>& dist, const RealType& x)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const weibull_distribution<%1%>, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_weibull_x(BOOST_CURRENT_FUNCTION, x, &result))
+ if(false == detail::check_weibull_x(function, x, &result, Policy()))
       return result;
 
- result = -boost::math::expm1(-pow(x / scale, shape));
+ result = -boost::math::expm1(-pow(x / scale, shape), Policy());
 
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const weibull_distribution<RealType>& dist, const RealType& p)
+template <class RealType, class Policy>
+inline RealType quantile(const weibull_distribution<RealType, Policy>& dist, const RealType& p)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const weibull_distribution<%1%>, %1%)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, p, &result))
+ if(false == detail::check_probability(function, p, &result, Policy()))
       return result;
 
    if(p == 1)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
- result = scale * pow(-boost::math::log1p(-p), 1 / shape);
+ result = scale * pow(-boost::math::log1p(-p, Policy()), 1 / shape);
 
    return result;
 }
 
-template <class RealType>
-inline RealType cdf(const complemented2_type<weibull_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType cdf(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::cdf(const weibull_distribution<%1%>, %1%)";
+
    RealType shape = c.dist.shape();
    RealType scale = c.dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_weibull_x(BOOST_CURRENT_FUNCTION, c.param, &result))
+ if(false == detail::check_weibull_x(function, c.param, &result, Policy()))
       return result;
 
    result = exp(-pow(c.param / scale, shape));
@@ -194,73 +205,81 @@
    return result;
 }
 
-template <class RealType>
-inline RealType quantile(const complemented2_type<weibull_distribution<RealType>, RealType>& c)
+template <class RealType, class Policy>
+inline RealType quantile(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::quantile(const weibull_distribution<%1%>, %1%)";
+
    RealType shape = c.dist.shape();
    RealType scale = c.dist.scale();
    RealType q = c.param;
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
- if(false == detail::check_probability(BOOST_CURRENT_FUNCTION, q, &result))
+ if(false == detail::check_probability(function, q, &result, Policy()))
       return result;
 
    if(q == 0)
- return tools::overflow_error<RealType>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<RealType>(function, 0, Policy());
 
    result = scale * pow(-log(q), 1 / shape);
 
    return result;
 }
 
-template <class RealType>
-inline RealType mean(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mean(const weibull_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::mean(const weibull_distribution<%1%>)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
 
- result = scale * boost::math::tgamma(1 + 1 / shape);
+ result = scale * boost::math::tgamma(1 + 1 / shape, Policy());
    return result;
 }
 
-template <class RealType>
-inline RealType variance(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType variance(const weibull_distribution<RealType, Policy>& dist)
 {
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
+ static const char* function = "boost::math::variance(const weibull_distribution<%1%>)";
+
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
    {
       return result;
    }
- result = boost::math::tgamma(1 + 1 / shape);
+ result = boost::math::tgamma(1 + 1 / shape, Policy());
    result *= -result;
- result += boost::math::tgamma(1 + 2 / shape);
+ result += boost::math::tgamma(1 + 2 / shape, Policy());
    result *= scale * scale;
    return result;
 }
 
-template <class RealType>
-inline RealType mode(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType mode(const weibull_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std function pow.
 
+ static const char* function = "boost::math::mode(const weibull_distribution<%1%>)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
    {
       return result;
    }
@@ -268,16 +287,18 @@
    return result;
 }
 
-template <class RealType>
-inline RealType median(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType median(const weibull_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std function pow.
 
+ static const char* function = "boost::math::median(const weibull_distribution<%1%>)";
+
    RealType shape = dist.shape(); // Wikipedia k
    RealType scale = dist.scale(); // Wikipedia lambda
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
    {
       return result;
    }
@@ -286,48 +307,52 @@
    return result;
 }
 
-template <class RealType>
-inline RealType skewness(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType skewness(const weibull_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::skewness(const weibull_distribution<%1%>)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
    {
       return result;
    }
    RealType g1, g2, g3, d;
 
- g1 = boost::math::tgamma(1 + 1 / shape);
- g2 = boost::math::tgamma(1 + 2 / shape);
- g3 = boost::math::tgamma(1 + 3 / shape);
+ g1 = boost::math::tgamma(1 + 1 / shape, Policy());
+ g2 = boost::math::tgamma(1 + 2 / shape, Policy());
+ g3 = boost::math::tgamma(1 + 3 / shape, Policy());
    d = pow(g2 - g1 * g1, RealType(1.5));
 
    result = (2 * g1 * g1 * g1 - 3 * g1 * g2 + g3) / d;
    return result;
 }
 
-template <class RealType>
-inline RealType kurtosis_excess(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis_excess(const weibull_distribution<RealType, Policy>& dist)
 {
    using namespace std; // for ADL of std functions
 
+ static const char* function = "boost::math::kurtosis_excess(const weibull_distribution<%1%>)";
+
    RealType shape = dist.shape();
    RealType scale = dist.scale();
 
    RealType result;
- if(false == detail::check_weibull(BOOST_CURRENT_FUNCTION, scale, shape, &result))
+ if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
       return result;
 
    RealType g1, g2, g3, g4, d, g1_2, g1_4;
 
- g1 = boost::math::tgamma(1 + 1 / shape);
- g2 = boost::math::tgamma(1 + 2 / shape);
- g3 = boost::math::tgamma(1 + 3 / shape);
- g4 = boost::math::tgamma(1 + 4 / shape);
+ g1 = boost::math::tgamma(1 + 1 / shape, Policy());
+ g2 = boost::math::tgamma(1 + 2 / shape, Policy());
+ g3 = boost::math::tgamma(1 + 3 / shape, Policy());
+ g4 = boost::math::tgamma(1 + 4 / shape, Policy());
    g1_2 = g1 * g1;
    g1_4 = g1_2 * g1_2;
    d = g2 - g1_2;
@@ -338,8 +363,8 @@
    return result;
 }
 
-template <class RealType>
-inline RealType kurtosis(const weibull_distribution<RealType>& dist)
+template <class RealType, class Policy>
+inline RealType kurtosis(const weibull_distribution<RealType, Policy>& dist)
 {
    return kurtosis_excess(dist) + 3;
 }

Added: sandbox/math_toolkit/boost/math/policy/error_handling.hpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/boost/math/policy/error_handling.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -0,0 +1,499 @@
+// Copyright John Maddock 2007.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MATH_POLICY_ERROR_HANDLING_HPP
+#define BOOST_MATH_POLICY_ERROR_HANDLING_HPP
+
+#include <stdexcept>
+#include <iomanip>
+#include <string>
+#include <cerrno>
+#include <cmath>
+#include <stdexcept>
+#include <boost/math/tools/config.hpp>
+#include <boost/math/policy/policy.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/cstdint.hpp>
+#ifdef BOOST_MSVC
+# pragma warning(push) // Quiet warnings in boost/format.hpp
+# pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE
+# pragma warning(disable: 4512) // assignment operator could not be generated.
+#endif
+#include <boost/format.hpp>
+#ifdef BOOST_MSVC
+# pragma warning(pop)
+#endif
+
+namespace boost{ namespace math{
+
+class evaluation_error : public std::runtime_error
+{
+public:
+ evaluation_error(const std::string& s) : std::runtime_error(s){}
+};
+
+namespace policy{
+//
+// Forward declarations of user error handlers,
+// it's up to the user to provide the definition of these:
+//
+template <class T>
+T user_domain_error(const char* function, const char* message, const T& val);
+template <class T>
+T user_pole_error(const char* function, const char* message, const T& val);
+template <class T>
+T user_overflow_error(const char* function, const char* message, const T& val);
+template <class T>
+T user_underflow_error(const char* function, const char* message, const T& val);
+template <class T>
+T user_denorm_error(const char* function, const char* message, const T& val);
+template <class T>
+T user_evaluation_error(const char* function, const char* message, const T& val);
+
+namespace detail{
+
+template <class E, class T>
+void raise_error(const char* function, const char* message)
+{
+ if(function == 0)
+ function = "Unknown function";
+ if(message == 0)
+ message = "Cause unknown";
+
+ std::string msg("Error in function ");
+ msg += (boost::format(function) % typeid(T).name()).str();
+ msg += ": ";
+ msg += message;
+
+ E e(msg);
+ boost::throw_exception(e);
+}
+
+template <class E, class T>
+void raise_error(const char* function, const char* message, const T& val)
+{
+ if(function == 0)
+ function = "Unknown function";
+ if(message == 0)
+ message = "Cause unknown";
+
+ std::string msg("Error in function ");
+ msg += (boost::format(function) % typeid(T).name()).str();
+ msg += ": ";
+ msg += message;
+
+ int prec = 2 + (boost::math::policy::digits<T, boost::math::policy::policy<> >() * 30103UL) / 100000UL;
+ msg = (boost::format(msg) % boost::io::group(std::setprecision(prec), val)).str();
+
+ E e(msg);
+ boost::throw_exception(e);
+}
+
+template <class T>
+inline T raise_domain_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::domain_error< ::boost::math::policy::throw_on_error>&)
+{
+ raise_error<std::domain_error, T>(function, message, val);
+ // we never get here:
+ return std::numeric_limits<T>::quiet_NaN();
+}
+
+template <class T>
+inline T raise_domain_error(
+ const char* ,
+ const char* ,
+ const T& ,
+ const ::boost::math::policy::domain_error< ::boost::math::policy::ignore_error>&)
+{
+ // This may or may not do the right thing, but the user asked for the error
+ // to be ignored so here we go anyway:
+ return std::numeric_limits<T>::quiet_NaN();
+}
+
+template <class T>
+inline T raise_domain_error(
+ const char* ,
+ const char* ,
+ const T& ,
+ const ::boost::math::policy::domain_error< ::boost::math::policy::errno_on_error>&)
+{
+ errno = EDOM;
+ // This may or may not do the right thing, but the user asked for the error
+ // to be silent so here we go anyway:
+ return std::numeric_limits<T>::quiet_NaN();
+}
+
+template <class T>
+inline T raise_domain_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::domain_error< ::boost::math::policy::user_error>&)
+{
+ return user_domain_error(function, message, val);
+}
+
+template <class T>
+inline T raise_pole_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::pole_error< ::boost::math::policy::throw_on_error>&)
+{
+ return boost::math::policy::detail::raise_domain_error(function, message, val, ::boost::math::policy::domain_error< ::boost::math::policy::throw_on_error>());
+}
+
+template <class T>
+inline T raise_pole_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::pole_error< ::boost::math::policy::ignore_error>&)
+{
+ return ::boost::math::policy::detail::raise_domain_error(function, message, val, ::boost::math::policy::domain_error< ::boost::math::policy::ignore_error>());
+}
+
+template <class T>
+inline T raise_pole_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::pole_error< ::boost::math::policy::errno_on_error>&)
+{
+ return ::boost::math::policy::detail::raise_domain_error(function, message, val, ::boost::math::policy::domain_error< ::boost::math::policy::errno_on_error>());
+}
+
+template <class T>
+inline T raise_pole_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::pole_error< ::boost::math::policy::user_error>&)
+{
+ return user_pole_error(function, message, val);
+}
+
+template <class T>
+inline T raise_overflow_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policy::overflow_error< ::boost::math::policy::throw_on_error>&)
+{
+ raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow");
+ // we never get here:
+ return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
+}
+
+template <class T>
+inline T raise_overflow_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policy::overflow_error< ::boost::math::policy::ignore_error>&)
+{
+ // This may or may not do the right thing, but the user asked for the error
+ // to be ignored so here we go anyway:
+ return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
+}
+
+template <class T>
+inline T raise_overflow_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policy::overflow_error< ::boost::math::policy::errno_on_error>&)
+{
+ errno = ERANGE;
+ // This may or may not do the right thing, but the user asked for the error
+ // to be silent so here we go anyway:
+ return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
+}
+
+template <class T>
+inline T raise_overflow_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policy::overflow_error< ::boost::math::policy::user_error>&)
+{
+ return user_overflow_error(function, message, std::numeric_limits<T>::infinity());
+}
+
+template <class T>
+inline T raise_underflow_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policy::underflow_error< ::boost::math::policy::throw_on_error>&)
+{
+ raise_error<std::underflow_error, T>(function, message ? message : "numeric underflow");
+ // we never get here:
+ return 0;
+}
+
+template <class T>
+inline T raise_underflow_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policy::underflow_error< ::boost::math::policy::ignore_error>&)
+{
+ // This may or may not do the right thing, but the user asked for the error
+ // to be ignored so here we go anyway:
+ return 0;
+}
+
+template <class T>
+inline T raise_underflow_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policy::underflow_error< ::boost::math::policy::errno_on_error>&)
+{
+ errno = ERANGE;
+ // This may or may not do the right thing, but the user asked for the error
+ // to be silent so here we go anyway:
+ return 0;
+}
+
+template <class T>
+inline T raise_underflow_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policy::underflow_error< ::boost::math::policy::user_error>&)
+{
+ return user_underflow_error(function, message, T(0));
+}
+
+template <class T>
+inline T raise_denorm_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::denorm_error< ::boost::math::policy::throw_on_error>&)
+{
+ raise_error<std::underflow_error, T>(function, message ? message : "denormalised result");
+ // we never get here:
+ return 0;
+}
+
+template <class T>
+inline T raise_denorm_error(
+ const char* ,
+ const char* ,
+ const T& val,
+ const ::boost::math::policy::denorm_error< ::boost::math::policy::ignore_error>&)
+{
+ // This may or may not do the right thing, but the user asked for the error
+ // to be ignored so here we go anyway:
+ return val;
+}
+
+template <class T>
+inline T raise_denorm_error(
+ const char* ,
+ const char* ,
+ const T& val,
+ const ::boost::math::policy::denorm_error< ::boost::math::policy::errno_on_error>&)
+{
+ errno = ERANGE;
+ // This may or may not do the right thing, but the user asked for the error
+ // to be silent so here we go anyway:
+ return val;
+}
+
+template <class T>
+inline T raise_denorm_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::denorm_error< ::boost::math::policy::user_error>&)
+{
+ return user_denorm_error(function, message, val);
+}
+
+template <class T>
+inline T raise_evaluation_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::evaluation_error< ::boost::math::policy::throw_on_error>&)
+{
+ raise_error<boost::math::evaluation_error, T>(function, message, val);
+ // we never get here:
+ return 0;
+}
+
+template <class T>
+inline T raise_evaluation_error(
+ const char* ,
+ const char* ,
+ const T& val,
+ const ::boost::math::policy::evaluation_error< ::boost::math::policy::ignore_error>&)
+{
+ // This may or may not do the right thing, but the user asked for the error
+ // to be ignored so here we go anyway:
+ return val;
+}
+
+template <class T>
+inline T raise_evaluation_error(
+ const char* ,
+ const char* ,
+ const T& val,
+ const ::boost::math::policy::evaluation_error< ::boost::math::policy::errno_on_error>&)
+{
+ errno = EDOM;
+ // This may or may not do the right thing, but the user asked for the error
+ // to be silent so here we go anyway:
+ return val;
+}
+
+template <class T>
+inline T raise_evaluation_error(
+ const char* function,
+ const char* message,
+ const T& val,
+ const ::boost::math::policy::evaluation_error< ::boost::math::policy::user_error>&)
+{
+ return user_evaluation_error(function, message, val);
+}
+
+} // namespace detail
+
+template <class T, class Policy>
+inline T raise_domain_error(const char* function, const char* message, const T& val, const Policy&)
+{
+ typedef typename Policy::domain_error_type policy_type;
+ return detail::raise_domain_error(
+ function, message ? message : "Domain Error evaluating function at %1%",
+ val, policy_type());
+}
+
+template <class T, class Policy>
+inline T raise_pole_error(const char* function, const char* message, const T& val, const Policy&)
+{
+ typedef typename Policy::pole_error_type policy_type;
+ return detail::raise_pole_error(
+ function, message ? message : "Evaluation of function at pole %1%",
+ val, policy_type());
+}
+
+template <class T, class Policy>
+inline T raise_overflow_error(const char* function, const char* message, const Policy&)
+{
+ typedef typename Policy::overflow_error_type policy_type;
+ return detail::raise_overflow_error<T>(
+ function, message ? message : "Overflow Error",
+ policy_type());
+}
+
+template <class T, class Policy>
+inline T raise_underflow_error(const char* function, const char* message, const Policy&)
+{
+ typedef typename Policy::underflow_error_type policy_type;
+ return detail::raise_underflow_error<T>(
+ function, message ? message : "Underflow Error",
+ policy_type());
+}
+
+template <class T, class Policy>
+inline T raise_denorm_error(const char* function, const char* message, const T& val, const Policy&)
+{
+ typedef typename Policy::denorm_error_type policy_type;
+ return detail::raise_denorm_error<T>(
+ function, message ? message : "Denorm Error",
+ val,
+ policy_type());
+}
+
+template <class T, class Policy>
+inline T raise_evaluation_error(const char* function, const char* message, const T& val, const Policy&)
+{
+ typedef typename Policy::evaluation_error_type policy_type;
+ return detail::raise_evaluation_error(
+ function, message ? message : "Internal Evaluation Error, best value so far was %1%",
+ val, policy_type());
+}
+
+//
+// checked_narrowing_cast:
+//
+namespace detail{
+
+template <class R, class T, class Policy>
+inline bool check_overflow(T val, R* result, const char* function, const Policy& pol)
+{
+ using namespace std;
+ if(fabs(val) > tools::max_value<R>())
+ {
+ *result = static_cast<R>(raise_overflow_error<R>(function, 0, pol));
+ return true;
+ }
+ return false;
+}
+template <class R, class T, class Policy>
+inline bool check_underflow(T val, R* result, const char* function, const Policy& pol)
+{
+ if((val != 0) && (static_cast<R>(val) == 0))
+ {
+ *result = static_cast<R>(raise_underflow_error<R>(function, 0, pol));
+ return true;
+ }
+ return false;
+}
+template <class R, class T, class Policy>
+inline bool check_denorm(T val, R* result, const char* function, const Policy& pol)
+{
+ using namespace std;
+ if((fabs(val) < static_cast<T>(tools::min_value<R>())) && (static_cast<R>(val) != 0))
+ {
+ *result = static_cast<R>(raise_denorm_error<R>(function, 0, static_cast<R>(val), pol));
+ return true;
+ }
+ return false;
+}
+
+template <class R, class T>
+inline bool check_overflow(T val, R* result, const char* function, const overflow_error<ignore_error>&){ return false; }
+template <class R, class T>
+inline bool check_underflow(T val, R* result, const char* function, const underflow_error<ignore_error>&){ return false; }
+template <class R, class T>
+inline bool check_denorm(T val, R* result, const char* function, const denorm_error<ignore_error>&){ return false; }
+
+}
+
+template <class R, class Policy, class T>
+inline R checked_narrowing_cast(T val, const char* function)
+{
+ typedef typename Policy::overflow_error_type overflow_type;
+ typedef typename Policy::underflow_error_type underflow_type;
+ typedef typename Policy::denorm_error_type denorm_type;
+ //
+ // Most of what follows will evaluate to a no-op:
+ //
+ R result;
+ if(detail::check_overflow<R>(val, &result, function, overflow_type()))
+ return result;
+ if(detail::check_underflow<R>(val, &result, function, underflow_type()))
+ return result;
+ if(detail::check_denorm<R>(val, &result, function, denorm_type()))
+ return result;
+
+ return static_cast<R>(val);
+}
+
+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)
+ raise_evaluation_error<boost::uintmax_t>(
+ function,
+ "Series evaluation exceeded %1% iterations, giving up now.", max_iter, pol);
+}
+
+} //namespace policy
+
+}} // namespaces boost/math
+
+#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP
+

Added: sandbox/math_toolkit/boost/math/policy/policy.hpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/boost/math/policy/policy.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -0,0 +1,698 @@
+// Copyright John Maddock 2007.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MATH_POLICY_HPP
+#define BOOST_MATH_POLICY_HPP
+
+#define BOOST_PARAMETER_MAX_ARITY 15
+
+#include <boost/mpl/list.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/find_if.hpp>
+#include <boost/mpl/remove_if.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/math/tools/config.hpp>
+#include <limits>
+
+namespace boost{ namespace math{ namespace policy{
+
+//
+// Define macros for our default policies, if they're not defined already:
+//
+#ifndef BOOST_MATH_DOMAIN_ERROR_POLICY
+#define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error
+#endif
+#ifndef BOOST_MATH_POLE_ERROR_POLICY
+#define BOOST_MATH_POLE_ERROR_POLICY throw_on_error
+#endif
+#ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error
+#endif
+#ifndef BOOST_MATH_EVALUATION_ERROR_POLICY
+#define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error
+#endif
+#ifndef BOOST_MATH_UNDERFLOW_ERROR_POLICY
+#define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error
+#endif
+#ifndef BOOST_MATH_DENORM_ERROR_POLICY
+#define BOOST_MATH_DENORM_ERROR_POLICY ignore_error
+#endif
+#ifndef BOOST_MATH_DIGITS10_POLICY
+#define BOOST_MATH_DIGITS10_POLICY 0
+#endif
+#ifndef BOOST_MATH_PROMOTE_FLOAT_POLICY
+#define BOOST_MATH_PROMOTE_FLOAT_POLICY true
+#endif
+#ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY
+#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
+#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
+#else
+#define BOOST_MATH_PROMOTE_DOUBLE_POLICY true
+#endif
+#endif
+#ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY
+#define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_outside
+#endif
+#ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY
+#define BOOST_MATH_ASSERT_UNDEFINED_POLICY true
+#endif
+
+#if !defined(__BORLANDC__)
+#define BOOST_MATH_META_INT(type, name, Default)\
+ template <type N = Default> struct name : public boost::mpl::int_<N>{};\
+ namespace detail{\
+ template <type N>\
+ char test_is_valid_arg(const name<N>*);\
+ char test_is_default_arg(const name<Default>*);\
+ template <class T> struct is_##name##_imp\
+ {\
+ template <type N> static char test(const name<N>*);\
+ static double test(...);\
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\
+ };\
+ }\
+ template <class T> struct is_##name : public boost::mpl::bool_<detail::is_##name##_imp<T>::value>{};
+
+#define BOOST_MATH_META_BOOL(name, Default)\
+ template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\
+ namespace detail{\
+ template <bool N>\
+ char test_is_valid_arg(const name<N>*);\
+ char test_is_default_arg(const name<Default>*);\
+ template <class T> struct is_##name##_imp\
+ {\
+ template <bool N> static char test(const name<N>*);\
+ static double test(...);\
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\
+ };\
+ }\
+ template <class T> struct is_##name : public boost::mpl::bool_<detail::is_##name##_imp<T>::value>{};
+#else
+#define BOOST_MATH_META_INT(Type, name, Default)\
+ template <Type N = Default> struct name : public boost::mpl::int_<N>{};\
+ namespace detail{\
+ template <Type N>\
+ char test_is_valid_arg(const name<N>*);\
+ char test_is_default_arg(const name<Default>*);\
+ template <class T> struct is_##name##_tester\
+ {\
+ template <Type N> static char test(const name<N>&);\
+ static double test(...);\
+ };\
+ template <class T> struct is_##name##_imp\
+ {\
+ static T inst;\
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(detail::is_##name##_tester<T>::test(inst)) == 1);\
+ };\
+ }\
+ template <class T> struct is_##name : public boost::mpl::bool_<detail::is_##name##_imp<T>::value>\
+ {\
+ template <class U> struct apply{ typedef is_##name<U> type; };\
+ };
+
+#define BOOST_MATH_META_BOOL(name, Default)\
+ template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\
+ namespace detail{\
+ template <bool N>\
+ char test_is_valid_arg(const name<N>*);\
+ char test_is_default_arg(const name<Default>*);\
+ template <class T> struct is_##name##_tester\
+ {\
+ template <bool N> static char test(const name<N>&);\
+ static double test(...);\
+ };\
+ template <class T> struct is_##name##_imp\
+ {\
+ static T inst;\
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(detail::is_##name##_tester<T>::test(inst)) == 1);\
+ };\
+ }\
+ template <class T> struct is_##name : public boost::mpl::bool_<detail::is_##name##_imp<T>::value>\
+ {\
+ template <class U> struct apply{ typedef is_##name<U> type; };\
+ };
+#endif
+//
+// Begin by defining policy types for error handling:
+//
+enum error_policy_type
+{
+ throw_on_error = 0,
+ errno_on_error = 1,
+ ignore_error = 2,
+ user_error = 3
+};
+
+BOOST_MATH_META_INT(error_policy_type, domain_error, BOOST_MATH_DOMAIN_ERROR_POLICY)
+BOOST_MATH_META_INT(error_policy_type, pole_error, BOOST_MATH_POLE_ERROR_POLICY)
+BOOST_MATH_META_INT(error_policy_type, overflow_error, BOOST_MATH_OVERFLOW_ERROR_POLICY)
+BOOST_MATH_META_INT(error_policy_type, underflow_error, BOOST_MATH_UNDERFLOW_ERROR_POLICY)
+BOOST_MATH_META_INT(error_policy_type, denorm_error, BOOST_MATH_DENORM_ERROR_POLICY)
+BOOST_MATH_META_INT(error_policy_type, evaluation_error, BOOST_MATH_EVALUATION_ERROR_POLICY)
+
+//
+// Policy types for internal promotion:
+//
+BOOST_MATH_META_BOOL(promote_float, BOOST_MATH_PROMOTE_FLOAT_POLICY);
+BOOST_MATH_META_BOOL(promote_double, BOOST_MATH_PROMOTE_DOUBLE_POLICY);
+BOOST_MATH_META_BOOL(assert_undefined, BOOST_MATH_ASSERT_UNDEFINED_POLICY);
+//
+// Policy types for discrete quantiles:
+//
+enum discrete_quantile_policy_type
+{
+ real,
+ integer_outside,
+ integer_inside,
+ integer_below,
+ integer_above,
+ integer_nearest
+};
+
+BOOST_MATH_META_INT(discrete_quantile_policy_type, discrete_quantile, BOOST_MATH_DISCRETE_QUANTILE_POLICY);
+//
+// Precision:
+//
+BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY);
+BOOST_MATH_META_INT(int, digits2, 0);
+//
+// Define the names for each possible policy:
+//
+#define BOOST_MATH_PARAMETER(name)\
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(name##_name)\
+ BOOST_PARAMETER_NAME(name##_name)
+
+struct default_policy{};
+
+namespace detail{
+//
+// Trait to work out bits precision from digits10 and digits2:
+//
+template <class Digits10, class Digits2>
+struct precision
+{
+ //
+ // Now work out the precision:
+ //
+ typedef typename mpl::if_c<
+ (Digits10::value == 0),
+ digits2<0>,
+ digits2<((Digits10::value + 1) * 1000L) / 301L>
+ >::type digits2_type;
+public:
+#ifdef __BORLANDC__
+ typedef typename mpl::if_c<
+ (Digits2::value > ::boost::math::policy::detail::precision<Digits10,Digits2>::digits2_type::value),
+ Digits2, digits2_type>::type type;
+#else
+ typedef typename mpl::if_c<
+ (Digits2::value > digits2_type::value),
+ Digits2, digits2_type>::type type;
+#endif
+};
+
+template <class A, class B, bool b>
+struct select_result
+{
+ typedef A type;
+};
+template <class A, class B>
+struct select_result<A, B, false>
+{
+ typedef typename mpl::deref<B>::type type;
+};
+
+template <class Seq, class Pred, class DefaultType>
+struct find_arg
+{
+private:
+ typedef typename mpl::find_if<Seq, Pred>::type iter;
+ typedef typename mpl::end<Seq>::type end_type;
+public:
+ typedef typename select_result<
+ DefaultType, iter,
+ ::boost::is_same<iter, end_type>::value>::type type;
+};
+
+double test_is_valid_arg(...);
+double test_is_default_arg(...);
+char test_is_valid_arg(const default_policy*);
+char test_is_default_arg(const default_policy*);
+
+template <class T>
+struct is_valid_policy_imp
+{
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(test_is_valid_arg(static_cast<T*>(0))) == 1);
+};
+
+template <class T>
+struct is_default_policy_imp
+{
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(test_is_default_arg(static_cast<T*>(0))) == 1);
+};
+
+template <class T> struct is_valid_policy
+: public mpl::bool_<
+ ::boost::math::policy::detail::is_valid_policy_imp<T>::value>
+{};
+
+template <class T> struct is_default_policy
+: public mpl::bool_<
+ ::boost::math::policy::detail::is_default_policy_imp<T>::value>
+{
+ template <class U>
+ struct apply
+ {
+ typedef is_default_policy<U> type;
+ };
+};
+
+template <class Seq, class T, int N>
+struct append_N
+{
+ typedef typename mpl::push_back<Seq, T>::type new_seq;
+ typedef typename append_N<new_seq, T, N-1>::type type;
+};
+
+template <class Seq, class T>
+struct append_N<Seq, T, 0>
+{
+ typedef Seq type;
+};
+
+//
+// Traits class to work out what template parameters our default
+// policy<> class will have when modified for forwarding:
+//
+template <bool f, bool d>
+struct default_args
+{
+ typedef promote_float<false> arg1;
+ typedef promote_double<false> arg2;
+};
+
+template <>
+struct default_args<false, false>
+{
+ typedef default_policy arg1;
+ typedef default_policy arg2;
+};
+
+template <>
+struct default_args<true, false>
+{
+ typedef promote_float<false> arg1;
+ typedef default_policy arg2;
+};
+
+template <>
+struct default_args<false, true>
+{
+ typedef promote_double<false> arg1;
+ typedef default_policy arg2;
+};
+
+typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg1 forwarding_arg1;
+typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg2 forwarding_arg2;
+
+} // detail
+//
+// Now define the policy type with enough arguments to handle all
+// the policies:
+//
+template <class A1 = default_policy,
+ class A2 = default_policy,
+ class A3 = default_policy,
+ class A4 = default_policy,
+ class A5 = default_policy,
+ class A6 = default_policy,
+ class A7 = default_policy,
+ class A8 = default_policy,
+ class A9 = default_policy,
+ class A10 = default_policy,
+ class A11 = default_policy>
+struct policy
+{
+private:
+ //
+ // Validate all our arguments:
+ //
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A1>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A2>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A3>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A4>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A5>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A6>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A7>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A8>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A9>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A10>::value);
+ BOOST_STATIC_ASSERT(::boost::math::policy::detail::is_valid_policy<A11>::value);
+ //
+ // Typelist of the arguments:
+ //
+ typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11> arg_list;
+
+public:
+ typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, domain_error<> >::type domain_error_type;
+ typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, pole_error<> >::type pole_error_type;
+ typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, overflow_error<> >::type overflow_error_type;
+ typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, underflow_error<> >::type underflow_error_type;
+ typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, denorm_error<> >::type denorm_error_type;
+ typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, evaluation_error<> >::type evaluation_error_type;
+private:
+ //
+ // Now work out the precision:
+ //
+ typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type;
+ typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, digits2<> >::type bits_precision_type;
+public:
+ typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type;
+ //
+ // Internal promotion:
+ //
+ typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, promote_float<> >::type promote_float_type;
+ typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, promote_double<> >::type promote_double_type;
+ //
+ // Discrete quantiles:
+ //
+ typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, discrete_quantile<> >::type discrete_quantile_type;
+ //
+ // Mathematically undefined properties:
+ //
+ typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type;
+};
+//
+// These full specializations are defined to reduce the amount of
+// template instantiations that have to take place when using the default
+// policies, they have quite a large impact on compile times:
+//
+template <>
+struct policy<default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy>
+{
+public:
+ typedef domain_error<> domain_error_type;
+ typedef pole_error<> pole_error_type;
+ typedef overflow_error<> overflow_error_type;
+ typedef underflow_error<> underflow_error_type;
+ typedef denorm_error<> denorm_error_type;
+ typedef evaluation_error<> evaluation_error_type;
+#if BOOST_MATH_DIGITS10_POLICY == 0
+ typedef digits2<> precision_type;
+#else
+ typedef detail::precision<digits10<>, digits2<> >::type precision_type;
+#endif
+ typedef promote_float<> promote_float_type;
+ typedef promote_double<> promote_double_type;
+ typedef discrete_quantile<> discrete_quantile_type;
+ typedef assert_undefined<> assert_undefined_type;
+};
+
+template <>
+struct policy<detail::forwarding_arg1, detail::forwarding_arg2, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy>
+{
+public:
+ typedef domain_error<> domain_error_type;
+ typedef pole_error<> pole_error_type;
+ typedef overflow_error<> overflow_error_type;
+ typedef underflow_error<> underflow_error_type;
+ typedef denorm_error<> denorm_error_type;
+ typedef evaluation_error<> evaluation_error_type;
+#if BOOST_MATH_DIGITS10_POLICY == 0
+ typedef digits2<> precision_type;
+#else
+ typedef detail::precision<digits10<>, digits2<> >::type precision_type;
+#endif
+ typedef promote_float<false> promote_float_type;
+ typedef promote_double<false> promote_double_type;
+ typedef discrete_quantile<> discrete_quantile_type;
+ typedef assert_undefined<> assert_undefined_type;
+};
+
+template <class Policy,
+ class A1 = default_policy,
+ class A2 = default_policy,
+ class A3 = default_policy,
+ class A4 = default_policy,
+ class A5 = default_policy,
+ class A6 = default_policy,
+ class A7 = default_policy,
+ class A8 = default_policy,
+ class A9 = default_policy,
+ class A10 = default_policy,
+ class A11 = default_policy>
+struct normalise
+{
+private:
+ typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11> 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;
+ typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, typename Policy::underflow_error_type >::type underflow_error_type;
+ typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, typename Policy::denorm_error_type >::type denorm_error_type;
+ typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, typename Policy::evaluation_error_type >::type evaluation_error_type;
+ //
+ // Now work out the precision:
+ //
+ typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type;
+ typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, typename Policy::precision_type >::type bits_precision_type;
+ typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type;
+ //
+ // Internal promotion:
+ //
+ typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, typename Policy::promote_float_type >::type promote_float_type;
+ typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, typename Policy::promote_double_type >::type promote_double_type;
+ //
+ // Discrete quantiles:
+ //
+ typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, typename Policy::discrete_quantile_type >::type discrete_quantile_type;
+ //
+ // Mathematically undefined properties:
+ //
+ typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type;
+ //
+ // Define a typelist of the policies:
+ //
+ typedef mpl::vector<
+ domain_error_type,
+ pole_error_type,
+ overflow_error_type,
+ underflow_error_type,
+ denorm_error_type,
+ evaluation_error_type,
+ precision_type,
+ promote_float_type,
+ promote_double_type,
+ discrete_quantile_type,
+ assert_undefined_type> result_list;
+ //
+ // Remove all the policies that are the same as the default:
+ //
+ typedef typename mpl::remove_if<result_list, detail::is_default_policy<mpl::_> >::type reduced_list;
+ //
+ // 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;
+public:
+ typedef policy<
+ typename mpl::at<result_type, mpl::int_<0> >::type,
+ typename mpl::at<result_type, mpl::int_<1> >::type,
+ typename mpl::at<result_type, mpl::int_<2> >::type,
+ typename mpl::at<result_type, mpl::int_<3> >::type,
+ typename mpl::at<result_type, mpl::int_<4> >::type,
+ typename mpl::at<result_type, mpl::int_<5> >::type,
+ typename mpl::at<result_type, mpl::int_<6> >::type,
+ 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;
+};
+//
+// Full specialisation to speed up compilation of the common case:
+//
+template <>
+struct normalise<policy<>,
+ promote_float<false>,
+ promote_double<false>,
+ discrete_quantile<>,
+ assert_undefined<>,
+ default_policy,
+ default_policy,
+ default_policy,
+ default_policy,
+ default_policy,
+ default_policy,
+ default_policy>
+{
+ typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type;
+};
+
+inline policy<> make_policy()
+{ return policy<>(); }
+
+template <class A1>
+inline typename normalise<policy<>, A1>::type make_policy(const A1&)
+{
+ typedef typename normalise<policy<>, A1>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2>
+inline typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&)
+{
+ typedef typename normalise<policy<>, A1, A2>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3>
+inline typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4>
+inline typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5, class A6>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type;
+ return result_type();
+}
+
+template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
+inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&)
+{
+ typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type;
+ return result_type();
+}
+
+//
+// Traits class to handle internal promotion:
+//
+template <class Real, class Policy>
+struct evaluation
+{
+ typedef Real type;
+};
+
+template <class Policy>
+struct evaluation<float, Policy>
+{
+ typedef typename mpl::if_<typename Policy::promote_float_type, double, float>::type type;
+};
+
+template <class Policy>
+struct evaluation<double, Policy>
+{
+ typedef typename mpl::if_<typename Policy::promote_double_type, long double, double>::type type;
+};
+
+template <class Real, class Policy>
+struct precision
+{
+ typedef typename Policy::precision_type precision_type;
+ typedef typename mpl::if_c<
+ ((std::numeric_limits<Real>::is_specialized == 0) || (std::numeric_limits<Real>::digits == 0)),
+ // Possibly unknown precision:
+ precision_type,
+ typename mpl::if_c<
+#ifndef __BORLANDC__
+ ((::std::numeric_limits<Real>::digits <= precision_type::value)
+ || (Policy::precision_type::value <= 0)),
+#else
+ ((::std::numeric_limits<Real>::digits <= ::boost::math::policy::precision<Real, Policy>::precision_type::value)
+ || (::boost::math::policy::precision<Real, Policy>::precision_type::value <= 0)),
+#endif
+ // Default case, full precision for RealType:
+ digits2< ::std::numeric_limits<Real>::digits>,
+ // User customised precision:
+ precision_type
+ >::type
+ >::type type;
+};
+
+template <class T, class Policy>
+inline int digits(BOOST_EXPLICIT_TEMPLATE_TYPE(T))
+{
+#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
+ BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
+#else
+ BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
+#endif
+ typedef typename precision<T, Policy>::type p_t;
+ return p_t::value;
+}
+
+namespace detail{
+
+template <class A1,
+ class A2,
+ class A3,
+ class A4,
+ class A5,
+ class A6,
+ class A7,
+ class A8,
+ class A9,
+ class A10,
+ class A11>
+char test_is_policy(const policy<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11>*);
+double test_is_policy(...);
+
+template <class P>
+struct is_policy_imp
+{
+ BOOST_STATIC_CONSTANT(bool, value = (sizeof(test_is_policy(static_cast<P*>(0))) == 1));
+};
+
+}
+
+template <class P>
+struct is_policy : public mpl::bool_< ::boost::math::policy::detail::is_policy_imp<P>::value> {};
+
+}}} // namespaces
+
+#endif // BOOST_MATH_POLICY_HPP
+

Modified: sandbox/math_toolkit/boost/math/special_functions/acosh.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/acosh.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/acosh.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -14,7 +14,7 @@
 #include <cmath>
 #include <boost/config.hpp>
 #include <boost/math/tools/precision.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 
 // This is the inverse of the hyperbolic cosine function.
@@ -36,8 +36,8 @@
         using ::std::numeric_limits;
 #endif
         
- template<typename T>
- inline T acosh_imp(const T x)
+ template<typename T, typename Policy>
+ inline T acosh_imp(const T x, const Policy& pol)
         {
             using ::std::abs;
             using ::std::sqrt;
@@ -52,9 +52,9 @@
             
             if(x < one)
             {
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "acosh requires x >= 1, but got x = %1%.", x);
+ return policy::raise_domain_error<T>(
+ "boost::math::acosh<%1%>(%1%)",
+ "acosh requires x >= 1, but got x = %1%.", x, pol);
             }
             else if (x >= taylor_n_bound)
             {
@@ -88,12 +88,19 @@
         }
        }
 
+ template<typename T, typename Policy>
+ inline typename tools::promote_args<T>::type acosh(const T x, const Policy& pol)
+ {
+ typedef typename tools::promote_args<T>::type result_type;
+ return detail::acosh_imp(
+ static_cast<result_type>(x), pol);
+ }
         template<typename T>
         inline typename tools::promote_args<T>::type acosh(const T x)
         {
            typedef typename tools::promote_args<T>::type result_type;
            return detail::acosh_imp(
- static_cast<result_type>(x));
+ static_cast<result_type>(x), policy::policy<>());
         }
 
     }

Modified: sandbox/math_toolkit/boost/math/special_functions/asinh.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/asinh.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/asinh.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -14,7 +14,6 @@
 #include <cmath>
 #include <boost/config.hpp>
 #include <boost/math/tools/precision.hpp>
-#include <boost/math/tools/error_handling.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 
 // This is the inverse of the hyperbolic sine function.
@@ -99,6 +98,13 @@
            return detail::asinh_imp(
               static_cast<result_type>(x));
         }
+ template<typename T, typename Policy>
+ inline typename tools::promote_args<T>::type asinh(const T x, const Policy&)
+ {
+ typedef typename tools::promote_args<T>::type result_type;
+ return detail::asinh_imp(
+ static_cast<result_type>(x));
+ }
 
     }
 }

Modified: sandbox/math_toolkit/boost/math/special_functions/atanh.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/atanh.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/atanh.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -14,7 +14,7 @@
 #include <cmath>
 #include <boost/config.hpp>
 #include <boost/math/tools/precision.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 
 // This is the inverse of the hyperbolic tangent function.
@@ -38,8 +38,8 @@
         
         // This is the main fare
         
- template<typename T>
- inline T atanh_imp(const T x)
+ template<typename T, typename Policy>
+ inline T atanh_imp(const T x, const Policy& pol)
         {
             using ::std::abs;
             using ::std::sqrt;
@@ -52,30 +52,30 @@
             
             static T const taylor_2_bound = sqrt(tools::epsilon<T>());
             static T const taylor_n_bound = sqrt(taylor_2_bound);
+
+ static const char* function = "boost::math::atanh<%1%>(%1%)";
             
             if (x < -one)
             {
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "atanh requires x >= -1, but got x = %1%.", x);
+ return policy::raise_domain_error<T>(
+ function,
+ "atanh requires x >= -1, but got x = %1%.", x, pol);
             }
             else if (x < -one + tools::epsilon<T>())
             {
                // -Infinity:
- return -tools::overflow_error<T>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
             }
             else if (x > one - tools::epsilon<T>())
             {
                // Infinity:
- return -tools::overflow_error<T>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
             }
             else if (x > +one)
             {
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "atanh requires x <= 1, but got x = %1%.", x);
+ return policy::raise_domain_error<T>(
+ function,
+ "atanh requires x <= 1, but got x = %1%.", x, pol);
             }
             else if (abs(x) >= taylor_n_bound)
             {
@@ -99,12 +99,19 @@
         }
        }
 
+ template<typename T, typename Policy>
+ inline typename tools::promote_args<T>::type atanh(const T x, const Policy& pol)
+ {
+ typedef typename tools::promote_args<T>::type result_type;
+ return detail::atanh_imp(
+ static_cast<result_type>(x), pol);
+ }
         template<typename T>
         inline typename tools::promote_args<T>::type atanh(const T x)
         {
            typedef typename tools::promote_args<T>::type result_type;
            return detail::atanh_imp(
- static_cast<result_type>(x));
+ static_cast<result_type>(x), policy::policy<>());
         }
 
     }

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -20,7 +20,6 @@
 #include <boost/math/special_functions/sin_pi.hpp>
 #include <boost/math/special_functions/cos_pi.hpp>
 #include <boost/math/special_functions/sinc.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
 #include <boost/math/tools/rational.hpp>
 #include <boost/math/tools/promotion.hpp>
 
@@ -28,31 +27,7 @@
 
 namespace detail{
 
-typedef mpl::int_<0> bessel_no_int_tag; // No integer optimisation possible.
-typedef mpl::int_<1> bessel_maybe_int_tag; // Maybe integer optimisation.
-typedef mpl::int_<2> bessel_int_tag; // Definite integer optimistaion.
-
-template <class T1, class T2>
-struct bessel_traits
-{
- typedef typename tools::promote_args<
- T1, T2
- >::type result_type;
-
- typedef typename mpl::if_c<
- (std::numeric_limits<result_type>::is_specialized == 0)
- || (std::numeric_limits<result_type>::digits == 0)
- || (std::numeric_limits<result_type>::digits > 64),
- bessel_no_int_tag,
- typename mpl::if_<
- is_integral<T1>,
- bessel_int_tag,
- bessel_maybe_int_tag
- >::type
- >::type optimisation_tag;
-};
-
-template <class T>
+template <class T, class Policy>
 struct bessel_j_small_z_series_term
 {
    typedef T result_type;
@@ -62,7 +37,7 @@
    {
       using namespace std;
       mult = x / 2;
- term = pow(mult, v) / tgamma(v+1);
+ term = pow(mult, v) / boost::math::tgamma(v+1, Policy());
       mult *= -mult;
    }
    T operator()()
@@ -79,7 +54,7 @@
    T term;
 };
 
-template <class T>
+template <class T, class Policy>
 struct sph_bessel_j_small_z_series_term
 {
    typedef T result_type;
@@ -89,7 +64,7 @@
    {
       using namespace std;
       mult = x / 2;
- term = pow(mult, T(v)) / tgamma(v+1+T(0.5f));
+ term = pow(mult, T(v)) / boost::math::tgamma(v+1+T(0.5f), Policy());
       mult *= -mult;
    }
    T operator()()
@@ -106,83 +81,84 @@
    T term;
 };
 
-template <class T>
-inline T bessel_j_small_z_series(T v, T x)
+template <class T, class Policy>
+inline T bessel_j_small_z_series(T v, T x, const Policy& pol)
 {
- bessel_j_small_z_series_term<T> s(v, x);
+ bessel_j_small_z_series_term<T, Policy> s(v, x);
    boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
- T result = boost::math::tools::sum_series(s, boost::math::tools::digits<T>(), max_iter);
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ T result = boost::math::tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter);
+ policy::check_series_iterations("boost::math::bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol);
    return result;
 }
 
-template <class T>
-inline T sph_bessel_j_small_z_series(unsigned v, T x)
+template <class T, class Policy>
+inline T sph_bessel_j_small_z_series(unsigned v, T x, const Policy& pol)
 {
    using namespace std; // ADL of std names
- sph_bessel_j_small_z_series_term<T> s(v, x);
+ sph_bessel_j_small_z_series_term<T, Policy> s(v, x);
    boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
- T result = boost::math::tools::sum_series(s, boost::math::tools::digits<T>(), max_iter);
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ T result = boost::math::tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter);
+ policy::check_series_iterations("boost::math::sph_bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol);
    return result * sqrt(constants::pi<T>() / 4);
 }
 
-template <class T>
-T cyl_bessel_j_imp(T v, T x, const bessel_no_int_tag& t)
+template <class T, class Policy>
+T cyl_bessel_j_imp(T v, T x, const bessel_no_int_tag& t, const Policy& pol)
 {
    using namespace std;
+ static const char* function = "boost::math::bessel_j<%1%>(%1%,%1%)";
    if(x < 0)
    {
       // better have integer v:
       if(floor(v) == v)
       {
- T r = cyl_bessel_j_imp(v, -x, t);
+ T r = cyl_bessel_j_imp(v, -x, t, pol);
          if(tools::real_cast<int>(v) & 1)
             r = -r;
          return r;
       }
       else
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but we need x >= 0", x);
+ return policy::raise_domain_error<T>(
+ function,
+ "Got x = %1%, but we need x >= 0", x, pol);
    }
    if(x == 0)
       return (v == 0) ? 1 : (v > 0) ? 0 :
- tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got v = %1%, but require v >= 0 or a negative integer: the result would be complex.", v);
+ policy::raise_domain_error<T>(
+ function,
+ "Got v = %1%, but require v >= 0 or a negative integer: the result would be complex.", v, pol);
    
    
    if((v >= 0) && ((x < 1) || (v > x * x / 4)))
    {
- return bessel_j_small_z_series(v, x);
+ return bessel_j_small_z_series(v, x, pol);
    }
    
    T j, y;
- bessel_jy(v, x, &j, &y, need_j);
+ bessel_jy(v, x, &j, &y, need_j, pol);
    return j;
 }
 
-template <class T>
-inline T cyl_bessel_j_imp(T v, T x, const bessel_maybe_int_tag&)
+template <class T, class Policy>
+inline T cyl_bessel_j_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
 {
    using namespace std; // ADL of std names.
- typedef typename bessel_asymptotic_tag<T>::type tag_type;
+ typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type;
    if((fabs(v) < 200) && (floor(v) == v))
    {
       if(fabs(x) > asymptotic_bessel_j_limit<T>(v, tag_type()))
          return asymptotic_bessel_j_large_x_2(v, x);
       else
- return bessel_jn(tools::real_cast<int>(v), x);
+ return bessel_jn(tools::real_cast<int>(v), x, pol);
    }
- return cyl_bessel_j_imp(v, x, bessel_no_int_tag());
+ return cyl_bessel_j_imp(v, x, bessel_no_int_tag(), pol);
 }
 
-template <class T>
-inline T cyl_bessel_j_imp(int v, T x, const bessel_int_tag&)
+template <class T, class Policy>
+inline T cyl_bessel_j_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
 {
    using namespace std;
- typedef typename bessel_asymptotic_tag<T>::type tag_type;
+ typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type;
    if(fabs(x) > asymptotic_bessel_j_limit<T>(abs(v), tag_type()))
    {
       T r = asymptotic_bessel_j_large_x_2(static_cast<T>(abs(v)), x);
@@ -191,37 +167,37 @@
       return r;
    }
    else
- return bessel_jn(v, x);
+ return bessel_jn(v, x, pol);
 }
 
-template <class T>
-inline T sph_bessel_j_imp(unsigned n, T x)
+template <class T, class Policy>
+inline T sph_bessel_j_imp(unsigned n, T x, const Policy& pol)
 {
    using namespace std; // ADL of std names
    if(x < 0)
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but function requires x > 0.", x);
+ return policy::raise_domain_error<T>(
+ "boost::math::sph_bessel_j<%1%>(%1%,%1%)",
+ "Got x = %1%, but function requires x > 0.", x, pol);
    //
    // Special case, n == 0 resolves down to the sinus cardinal of x:
    //
    if(n == 0)
- return boost::math::sinc_pi(x);
+ return boost::math::sinc_pi(x, pol);
    //
    // When x is small we may end up with 0/0, use series evaluation
    // instead, especially as it converges rapidly:
    //
    if(x < 1)
- return sph_bessel_j_small_z_series(n, x);
+ return sph_bessel_j_small_z_series(n, x, pol);
    //
    // Default case is just a naive evaluation of the definition:
    //
    return sqrt(constants::pi<T>() / (2 * x))
- * cyl_bessel_j_imp(T(n)+T(0.5f), x, bessel_no_int_tag());
+ * cyl_bessel_j_imp(T(n)+T(0.5f), x, bessel_no_int_tag(), pol);
 }
 
-template <class T>
-T cyl_bessel_i_imp(T v, T x)
+template <class T, class Policy>
+T cyl_bessel_i_imp(T v, T x, const Policy& pol)
 {
    //
    // This handles all the bessel I functions, note that we don't optimise
@@ -235,15 +211,15 @@
       // better have integer v:
       if(floor(v) == v)
       {
- T r = cyl_bessel_i_imp(v, -x);
+ T r = cyl_bessel_i_imp(v, -x, pol);
          if(tools::real_cast<int>(v) & 1)
             r = -r;
          return r;
       }
       else
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but we need x >= 0", x);
+ return policy::raise_domain_error<T>(
+ "boost::math::cyl_bessel_i<%1%>(%1%,%1%)",
+ "Got x = %1%, but we need x >= 0", x, pol);
    }
    if(x == 0)
    {
@@ -255,7 +231,7 @@
       T e = exp(x / 2);
       return e * (e / sqrt(2 * x * constants::pi<T>()));
    }
- if(tools::digits<T>() <= 64)
+ if(policy::digits<T, Policy>() <= 64)
    {
       if(v == 0)
       {
@@ -267,77 +243,79 @@
       }
    }
    T I, K;
- bessel_ik(v, x, &I, &K, need_i);
+ bessel_ik(v, x, &I, &K, need_i, pol);
    return I;
 }
 
-template <class T>
-inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& t)
+template <class T, class Policy>
+inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& t, const Policy& pol)
 {
+ static const char* function = "boost::math::cyl_bessel_k<%1%>(%1%,%1%)";
    using namespace std;
    if(x < 0)
    {
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but we need x > 0", x);
+ return policy::raise_domain_error<T>(
+ function,
+ "Got x = %1%, but we need x > 0", x, pol);
    }
    if(x == 0)
    {
- return (v == 0) ? tools::overflow_error<T>(BOOST_CURRENT_FUNCTION)
- : tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but we need x > 0", x);
+ return (v == 0) ? policy::raise_overflow_error<T>(function, 0, pol)
+ : policy::raise_domain_error<T>(
+ function,
+ "Got x = %1%, but we need x > 0", x, pol);
    }
    T I, K;
- bessel_ik(v, x, &I, &K, need_k);
+ bessel_ik(v, x, &I, &K, need_k, pol);
    return K;
 }
 
-template <class T>
-inline T cyl_bessel_k_imp(T v, T x, const bessel_maybe_int_tag&)
+template <class T, class Policy>
+inline T cyl_bessel_k_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
 {
    using namespace std;
    if((floor(v) == v))
    {
- return bessel_kn(tools::real_cast<int>(v), x);
+ return bessel_kn(tools::real_cast<int>(v), x, pol);
    }
- return cyl_bessel_k_imp(v, x, bessel_no_int_tag());
+ return cyl_bessel_k_imp(v, x, bessel_no_int_tag(), pol);
 }
 
-template <class T>
-inline T cyl_bessel_k_imp(int v, T x, const bessel_int_tag&)
+template <class T, class Policy>
+inline T cyl_bessel_k_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
 {
- return bessel_kn(v, x);
+ return bessel_kn(v, x, pol);
 }
 
-template <class T>
-inline T cyl_neumann_imp(T v, T x, const bessel_no_int_tag&)
+template <class T, class Policy>
+inline T cyl_neumann_imp(T v, T x, const bessel_no_int_tag&, const Policy& pol)
 {
+ static const char* function = "boost::math::cyl_neumann<%1%>(%1%,%1%)";
    if(x <= 0)
    {
       return (v == 0) && (x == 0) ?
- tools::overflow_error<T>(BOOST_CURRENT_FUNCTION)
- : tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but result is complex for x <= 0", x);
+ policy::raise_overflow_error<T>(function, 0, pol)
+ : policy::raise_domain_error<T>(
+ function,
+ "Got x = %1%, but result is complex for x <= 0", x, pol);
    }
    T j, y;
- bessel_jy(v, x, &j, &y, need_y);
+ bessel_jy(v, x, &j, &y, need_y, pol);
    //
    // Post evaluation check for internal overflow during evaluation,
    // can occur when x is small and v is large, in which case the result
    // is -INF:
    //
    if(!(boost::math::isfinite)(y))
- return -tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
    return y;
 }
 
-template <class T>
-inline T cyl_neumann_imp(T v, T x, const bessel_maybe_int_tag&)
+template <class T, class Policy>
+inline T cyl_neumann_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
 {
    using namespace std;
- typedef typename bessel_asymptotic_tag<T>::type tag_type;
+ typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type;
    if(floor(v) == v)
    {
       if((fabs(x) > asymptotic_bessel_y_limit<T>(tag_type())) && (fabs(x) > 5 * abs(v)))
@@ -348,16 +326,16 @@
          return r;
       }
       else
- return bessel_yn(tools::real_cast<int>(v), x);
+ return bessel_yn(tools::real_cast<int>(v), x, pol);
    }
- return cyl_neumann_imp<T>(v, x, bessel_no_int_tag());
+ return cyl_neumann_imp<T>(v, x, bessel_no_int_tag(), pol);
 }
 
-template <class T>
-inline T cyl_neumann_imp(int v, T x, const bessel_int_tag&)
+template <class T, class Policy>
+inline T cyl_neumann_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
 {
    using namespace std;
- typedef typename bessel_asymptotic_tag<T>::type tag_type;
+ typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type;
    if((fabs(x) > asymptotic_bessel_y_limit<T>(tag_type())) && (fabs(x) > 5 * abs(v)))
    {
       T r = asymptotic_bessel_y_large_x_2(static_cast<T>(abs(v)), x);
@@ -366,91 +344,128 @@
       return r;
    }
    else
- return bessel_yn(tools::real_cast<int>(v), x);
+ return bessel_yn(tools::real_cast<int>(v), x, pol);
 }
 
-template <class T>
-inline T sph_neumann_imp(unsigned v, T x)
+template <class T, class Policy>
+inline T sph_neumann_imp(unsigned v, T x, const Policy& pol)
 {
    using namespace std; // ADL of std names
+ static const char* function = "boost::math::sph_neumann<%1%>(%1%,%1%)";
    //
    // Nothing much to do here but check for errors, and
    // evaluate the function's definition directly:
    //
    if(x < 0)
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but function requires x > 0.", x);
+ return policy::raise_domain_error<T>(
+ function,
+ "Got x = %1%, but function requires x > 0.", x, pol);
 
    if(x < 2 * tools::min_value<T>())
- return -tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
 
- T result = cyl_neumann_imp(T(v)+0.5f, x, bessel_no_int_tag());
+ T result = cyl_neumann_imp(T(v)+0.5f, x, bessel_no_int_tag(), pol);
    T tx = sqrt(constants::pi<T>() / (2 * x));
 
    if((tx > 1) && (tools::max_value<T>() / tx < result))
- return -tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
 
    return result * tx;
 }
 
 } // namespace detail
 
+template <class T1, class T2, class Policy>
+inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
+ typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_j_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_bessel_j<%1%>(%1%,%1%)");
+}
+
 template <class T1, class T2>
-inline typename detail::bessel_traits<T1, T2>::result_type cyl_bessel_j(T1 v, T2 x)
+inline typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_j(T1 v, T2 x)
+{
+ return cyl_bessel_j(v, x, policy::policy<>());
+}
+
+template <class T, class Policy>
+inline typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T1, T2>::result_type result_type;
- typedef typename detail::bessel_traits<T1, T2>::optimisation_tag tag_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::cyl_bessel_j_imp<value_type>(v, static_cast<value_type>(x), tag_type()), BOOST_CURRENT_FUNCTION);
+ typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::sph_bessel_j_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::sph_bessel<%1%>(%1%,%1%)");
 }
 
 template <class T>
-inline typename detail::bessel_traits<T, T>::result_type sph_bessel(unsigned v, T x)
+inline typename detail::bessel_traits<T, T, policy::policy<> >::result_type sph_bessel(unsigned v, T x)
+{
+ return sph_bessel(v, x, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T, T>::result_type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::sph_bessel_j_imp<value_type>(v, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_i_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::cyl_bessel_i<%1%>(%1%,%1%)");
 }
 
 template <class T1, class T2>
-inline typename detail::bessel_traits<T1, T2>::result_type cyl_bessel_i(T1 v, T2 x)
+inline typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_i(T1 v, T2 x)
+{
+ return cyl_bessel_i(v, x, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T1, T2>::result_type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::cyl_bessel_i_imp<value_type>(v, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
+ typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_k_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_bessel_k<%1%>(%1%,%1%)");
 }
 
 template <class T1, class T2>
-inline typename detail::bessel_traits<T1, T2>::result_type cyl_bessel_k(T1 v, T2 x)
+inline typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_k(T1 v, T2 x)
+{
+ return cyl_bessel_k(v, x, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T1, T2>::result_type result_type;
- typedef typename detail::bessel_traits<T1, T2>::optimisation_tag tag_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::cyl_bessel_k_imp<value_type>(v, static_cast<value_type>(x), tag_type()), BOOST_CURRENT_FUNCTION);
+ typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
+ typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::cyl_neumann_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_neumann<%1%>(%1%,%1%)");
 }
 
 template <class T1, class T2>
-inline typename detail::bessel_traits<T1, T2>::result_type cyl_neumann(T1 v, T2 x)
+inline typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_neumann(T1 v, T2 x)
+{
+ return cyl_neumann(v, x, policy::policy<>());
+}
+
+template <class T, class Policy>
+inline typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T1, T2>::result_type result_type;
- typedef typename detail::bessel_traits<T1, T2>::optimisation_tag tag_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::cyl_neumann_imp<value_type>(v, static_cast<value_type>(x), tag_type()), BOOST_CURRENT_FUNCTION);
+ typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::sph_neumann_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::sph_neumann<%1%>(%1%,%1%)");
 }
 
 template <class T>
-inline typename detail::bessel_traits<T, T>::result_type sph_neumann(unsigned v, T x)
+inline typename detail::bessel_traits<T, T, policy::policy<> >::result_type sph_neumann(unsigned v, T x)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename detail::bessel_traits<T, T>::result_type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::sph_neumann_imp<value_type>(v, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ return sph_neumann(v, x, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -24,15 +24,15 @@
 //
 // Implementation of Beta(a,b) using the Lanczos approximation:
 //
-template <class T, class L>
-T beta_imp(T a, T b, const L&)
+template <class T, class L, class Policy>
+T beta_imp(T a, T b, const L&, const Policy& pol)
 {
    using namespace std; // for ADL of std names
 
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The arguments to the beta function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The arguments to the beta function must be greater than zero (got b=%1%).", b);
+ policy::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got b=%1%).", b, pol);
 
    T result;
 
@@ -41,9 +41,9 @@
 
    // Special cases:
    if((c == a) && (b < tools::epsilon<T>()))
- return boost::math::tgamma(b);
+ return boost::math::tgamma(b, pol);
    else if((c == b) && (a < tools::epsilon<T>()))
- return boost::math::tgamma(a);
+ return boost::math::tgamma(a, pol);
    if(b == 1)
       return 1/a;
    else if(a == 1)
@@ -71,6 +71,7 @@
       b += 1;
    }
    */
+
    if(a < b)
       std::swap(a, b);
 
@@ -84,7 +85,7 @@
    {
       // Special case where the base of the power term is close to 1
       // compute (1+x)^y instead:
- result *= exp(ambh * boost::math::log1p(-b / cgh));
+ result *= exp(ambh * boost::math::log1p(-b / cgh, pol));
    }
    else
    {
@@ -107,15 +108,15 @@
 // Generic implementation of Beta(a,b) without Lanczos approximation support
 // (Caution this is slow!!!):
 //
-template <class T>
-T beta_imp(T a, T b, const lanczos::undefined_lanczos& /* l */)
+template <class T, class Policy>
+T beta_imp(T a, T b, const lanczos::undefined_lanczos& /* l */, const Policy& pol)
 {
    using namespace std;
 
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The arguments to the beta function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The arguments to the beta function must be greater than zero (got b=%1%).", b);
+ policy::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got b=%1%).", b, pol);
 
    T result;
 
@@ -124,9 +125,9 @@
 
    // special cases:
    if((c == a) && (b < tools::epsilon<T>()))
- return boost::math::tgamma(b);
+ return boost::math::tgamma(b, pol);
    else if((c == b) && (a < tools::epsilon<T>()))
- return boost::math::tgamma(a);
+ return boost::math::tgamma(a, pol);
    if(b == 1)
       return 1/a;
    else if(a == 1)
@@ -154,12 +155,12 @@
    T lc = (std::max)(T(10), a+b);
 
    // calculate the fraction parts:
- T sa = detail::lower_gamma_series(a, la, ::boost::math::tools::digits<T>()) / a;
- sa += detail::upper_gamma_fraction(a, la, ::boost::math::tools::digits<T>());
- T sb = detail::lower_gamma_series(b, lb, ::boost::math::tools::digits<T>()) / b;
- sb += detail::upper_gamma_fraction(b, lb, ::boost::math::tools::digits<T>());
- T sc = detail::lower_gamma_series(c, lc, ::boost::math::tools::digits<T>()) / c;
- sc += detail::upper_gamma_fraction(c, lc, ::boost::math::tools::digits<T>());
+ T sa = detail::lower_gamma_series(a, la, pol) / a;
+ sa += detail::upper_gamma_fraction(a, la, ::boost::math::policy::digits<T, Policy>());
+ T sb = detail::lower_gamma_series(b, lb, pol) / b;
+ sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policy::digits<T, Policy>());
+ T sc = detail::lower_gamma_series(c, lc, pol) / c;
+ sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policy::digits<T, Policy>());
 
    // and the exponent part:
    result = exp(lc - la - lb) * pow(la/lc, a) * pow(lb/lc, b);
@@ -185,13 +186,14 @@
 // powers are *hard* though, and using logarithms just leads to
 // horrendous cancellation errors.
 //
-template <class T, class L>
+template <class T, class L, class Policy>
 T ibeta_power_terms(T a,
                         T b,
                         T x,
                         T y,
                         const L&,
- bool normalised)
+ bool normalised,
+ const Policy& pol)
 {
    using namespace std;
 
@@ -235,11 +237,11 @@
          // since one of the power terms will evaluate to a number close to 1.
          //
          if(fabs(l1) < 0.1)
- result *= exp(a * boost::math::log1p(l1));
+ result *= exp(a * boost::math::log1p(l1, pol));
          else
             result *= pow((x * cgh) / agh, a);
          if(fabs(l2) < 0.1)
- result *= exp(b * boost::math::log1p(l2));
+ result *= exp(b * boost::math::log1p(l2, pol));
          else
             result *= pow((y * cgh) / bgh, b);
       }
@@ -268,30 +270,30 @@
          T ratio = b / a;
          if((small_a && (ratio * l2 < 0.1)) || (!small_a && (l1 / ratio > 0.1)))
          {
- T l3 = boost::math::expm1(ratio * boost::math::log1p(l2));
+ T l3 = boost::math::expm1(ratio * boost::math::log1p(l2, pol), pol);
             l3 = l1 + l3 + l3 * l1;
- l3 = a * boost::math::log1p(l3);
+ l3 = a * boost::math::log1p(l3, pol);
             result *= exp(l3);
          }
          else
          {
- T l3 = boost::math::expm1(boost::math::log1p(l1) / ratio);
+ T l3 = boost::math::expm1(boost::math::log1p(l1, pol) / ratio, pol);
             l3 = l2 + l3 + l3 * l2;
- l3 = b * boost::math::log1p(l3);
+ l3 = b * boost::math::log1p(l3, pol);
             result *= exp(l3);
          }
       }
       else if(fabs(l1) < fabs(l2))
       {
          // First base near 1 only:
- T l = a * boost::math::log1p(l1)
+ T l = a * boost::math::log1p(l1, pol)
             + b * log((y * cgh) / bgh);
          result *= exp(l);
       }
       else
       {
          // Second base near 1 only:
- T l = b * boost::math::log1p(l2)
+ T l = b * boost::math::log1p(l2, pol)
             + a * log((x * cgh) / agh);
          result *= exp(l);
       }
@@ -341,13 +343,14 @@
 //
 // This version is generic, slow, and does not use the Lanczos approximation.
 //
-template <class T>
+template <class T, class Policy>
 T ibeta_power_terms(T a,
                         T b,
                         T x,
                         T y,
                         const boost::math::lanczos::undefined_lanczos&,
- bool normalised)
+ bool normalised,
+ const Policy& pol)
 {
    using namespace std;
 
@@ -369,12 +372,12 @@
    T lb = b + 5;
    T lc = a + b + 5;
    // gamma function partials:
- T sa = detail::lower_gamma_series(a, la, ::boost::math::tools::digits<T>()) / a;
- sa += detail::upper_gamma_fraction(a, la, ::boost::math::tools::digits<T>());
- T sb = detail::lower_gamma_series(b, lb, ::boost::math::tools::digits<T>()) / b;
- sb += detail::upper_gamma_fraction(b, lb, ::boost::math::tools::digits<T>());
- T sc = detail::lower_gamma_series(c, lc, ::boost::math::tools::digits<T>()) / c;
- sc += detail::upper_gamma_fraction(c, lc, ::boost::math::tools::digits<T>());
+ T sa = detail::lower_gamma_series(a, la, pol) / a;
+ sa += detail::upper_gamma_fraction(a, la, ::boost::math::policy::digits<T, Policy>());
+ T sb = detail::lower_gamma_series(b, lb, pol) / b;
+ sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policy::digits<T, Policy>());
+ T sc = detail::lower_gamma_series(c, lc, pol) / c;
+ sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policy::digits<T, Policy>());
    // gamma function powers combined with incomplete beta powers:
 
    T b1 = (x * lc) / la;
@@ -397,11 +400,11 @@
    {
       T p1, p2;
       if((fabs(b1 - 1) * a < 10) && (a > 1))
- p1 = exp(a * boost::math::log1p((x * b - y * la) / la));
+ p1 = exp(a * boost::math::log1p((x * b - y * la) / la, pol));
       else
          p1 = pow(b1, a);
       if((fabs(b2 - 1) * b < 10) && (b > 1))
- p2 = exp(b * boost::math::log1p((y * a - x * lb) / lb));
+ p2 = exp(b * boost::math::log1p((y * a - x * lb) / lb, pol));
       else
          p2 = pow(b2, b);
       T p3 = exp(e1);
@@ -434,8 +437,8 @@
    int n;
 };
 
-template <class T, class L>
-T ibeta_series(T a, T b, T x, T s0, const L&, bool normalised, T* p_derivative, T y)
+template <class T, class L, class Policy>
+T ibeta_series(T a, T b, T x, T s0, const L&, bool normalised, T* p_derivative, T y, const Policy& pol)
 {
    using namespace std;
 
@@ -453,7 +456,7 @@
       T cgh = c + L::g() - T(0.5);
       result = L::lanczos_sum_expG_scaled(c) / (L::lanczos_sum_expG_scaled(a) * L::lanczos_sum_expG_scaled(b));
       if(a * b < bgh * 10)
- result *= exp((b - 0.5f) * boost::math::log1p(a / bgh));
+ result *= exp((b - 0.5f) * boost::math::log1p(a / bgh, pol));
       else
          result *= pow(cgh / bgh, b - 0.5f);
       result *= pow(x * cgh / agh, a);
@@ -474,15 +477,15 @@
       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;
- result = boost::math::tools::sum_series(s, boost::math::tools::digits<T>(), max_iter, s0);
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ result = boost::math::tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter, s0);
+ policy::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%)", max_iter, pol);
    return result;
 }
 //
 // Incomplete Beta series again, this time without Lanczos support:
 //
-template <class T>
-T ibeta_series(T a, T b, T x, T s0, const boost::math::lanczos::undefined_lanczos&, bool normalised, T* p_derivative, T y)
+template <class T, class Policy>
+T ibeta_series(T a, T b, T x, T s0, const boost::math::lanczos::undefined_lanczos&, bool normalised, T* p_derivative, T y, const Policy& pol)
 {
    using namespace std;
 
@@ -503,12 +506,12 @@
       T lc = a + b + 5;
 
       // calculate the gamma parts:
- T sa = detail::lower_gamma_series(a, la, ::boost::math::tools::digits<T>()) / a;
- sa += detail::upper_gamma_fraction(a, la, ::boost::math::tools::digits<T>());
- T sb = detail::lower_gamma_series(b, lb, ::boost::math::tools::digits<T>()) / b;
- sb += detail::upper_gamma_fraction(b, lb, ::boost::math::tools::digits<T>());
- T sc = detail::lower_gamma_series(c, lc, ::boost::math::tools::digits<T>()) / c;
- sc += detail::upper_gamma_fraction(c, lc, ::boost::math::tools::digits<T>());
+ T sa = detail::lower_gamma_series(a, la, pol) / a;
+ sa += detail::upper_gamma_fraction(a, la, ::boost::math::policy::digits<T, Policy>());
+ T sb = detail::lower_gamma_series(b, lb, pol) / b;
+ sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policy::digits<T, Policy>());
+ T sc = detail::lower_gamma_series(c, lc, pol) / c;
+ sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policy::digits<T, Policy>());
 
       // and their combined power-terms:
       T b1 = (x * lc) / la;
@@ -531,7 +534,7 @@
       {
          result = pow(b1, a);
          if(a * b < lb * 10)
- result *= exp(b * boost::math::log1p(a / lb));
+ result *= exp(b * boost::math::log1p(a / lb, pol));
          else
             result *= pow(b2, b);
          result /= exp(e1);
@@ -554,8 +557,8 @@
       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;
- result = boost::math::tools::sum_series(s, boost::math::tools::digits<T>(), max_iter, s0);
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ result = boost::math::tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter, s0);
+ policy::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%)", max_iter, pol);
    return result;
 }
 
@@ -591,11 +594,12 @@
 //
 // Evaluate the incomplete beta via the continued fraction representation:
 //
-template <class T, class L>
-inline T ibeta_fraction2(T a, T b, T x, T y, const L& l, bool normalised, T* p_derivative)
+template <class T, class Policy>
+inline T ibeta_fraction2(T a, T b, T x, T y, const Policy& pol, bool normalised, T* p_derivative)
 {
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
    using namespace std;
- T result = ibeta_power_terms(a, b, x, y, l, normalised);
+ T result = ibeta_power_terms(a, b, x, y, lanczos_type(), normalised, pol);
    if(p_derivative)
    {
       *p_derivative = result;
@@ -605,16 +609,17 @@
       return result;
 
    ibeta_fraction2_t<T> f(a, b, x);
- T fract = boost::math::tools::continued_fraction_b(f, boost::math::tools::digits<T>());
+ T fract = boost::math::tools::continued_fraction_b(f, boost::math::policy::digits<T, Policy>());
    return result / fract;
 }
 //
 // Computes the difference between ibeta(a,b,x) and ibeta(a+k,b,x):
 //
-template <class T, class L>
-T ibeta_a_step(T a, T b, T x, T y, int k, const L& l, bool normalised, T* p_derivative)
+template <class T, class Policy>
+T ibeta_a_step(T a, T b, T x, T y, int k, const Policy& pol, bool normalised, T* p_derivative)
 {
- T prefix = ibeta_power_terms(a, b, x, y, l, normalised);
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
+ T prefix = ibeta_power_terms(a, b, x, y, lanczos_type(), normalised, pol);
    if(p_derivative)
    {
       *p_derivative = prefix;
@@ -694,9 +699,10 @@
    BOOST_STATIC_ASSERT(::boost::math::max_factorial<long double>::value >= 100);
 };
 
-template <class T, class L>
-T beta_small_b_large_a_series(T a, T b, T x, T y, T s0, T mult, const L& l, bool normalised)
+template <class T, class Policy>
+T beta_small_b_large_a_series(T a, T b, T x, T y, T s0, T mult, const Policy& pol, bool normalised)
 {
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
    using namespace std;
    //
    // This is DiDonato and Morris's BGRAT routine, see Eq's 9 through 9.6.
@@ -707,23 +713,23 @@
    T t = a + bm1 / 2;
    T lx, u;
    if(y < 0.35)
- lx = boost::math::log1p(-y);
+ lx = boost::math::log1p(-y, pol);
    else
       lx = log(x);
    u = -t * lx;
    // and from from 9.2:
    T prefix;
- T h = regularised_gamma_prefix(b, u, l);
+ T h = regularised_gamma_prefix(b, u, pol, lanczos_type());
    if(h <= tools::min_value<T>())
       return s0;
    if(normalised)
    {
- prefix = h / tgamma_delta_ratio_imp(a, b, l);
+ prefix = h / tgamma_delta_ratio(a, b, pol);
       prefix /= pow(t, b);
    }
    else
    {
- prefix = full_igamma_prefix(b, u) / pow(t, b);
+ prefix = full_igamma_prefix(b, u, pol) / pow(t, b);
    }
    prefix *= mult;
    //
@@ -735,7 +741,7 @@
    //
    // Now an initial value for J, see 9.6:
    //
- T j = gamma_q(b, u) / h;
+ T j = gamma_q(b, u, pol) / h;
    //
    // Now we can start to pull things together and evaluate the sum in Eq 9:
    //
@@ -827,9 +833,11 @@
 // input range and select the right implementation method for
 // each domain:
 //
-template <class T, class L>
-T ibeta_imp(T a, T b, T x, const L& l, bool inv, bool normalised, T* p_derivative)
+template <class T, class Policy>
+T ibeta_imp(T a, T b, T x, const Policy& pol, bool inv, bool normalised, T* p_derivative)
 {
+ static const char* function = "boost::math::ibeta<%1%>(%1%, %1%, %1%)";
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
    using namespace std; // for ADL of std math functions.
 
    bool invert = inv;
@@ -851,11 +859,11 @@
    }
 
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b);
+ policy::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b, pol);
    if((x < 0) || (x > 1))
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x);
+ policy::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol);
 
    if(x == 0)
    {
@@ -863,7 +871,7 @@
       {
          *p_derivative = (a == 1) ? 1 : (a < 1) ? tools::max_value<T>() / 2 : tools::min_value<T>() * 2;
       }
- return (invert ? (normalised ? 1 : beta_imp(a, b, l)) : 0);
+ return (invert ? (normalised ? 1 : boost::math::beta(a, b, pol)) : 0);
    }
    if(x == 1)
    {
@@ -871,7 +879,7 @@
       {
          *p_derivative = (b == 1) ? 1 : (b < 1) ? tools::max_value<T>() / 2 : tools::min_value<T>() * 2;
       }
- return (invert == 0 ? (normalised ? 1 : beta_imp(a, b, l)) : 0);
+ return (invert == 0 ? (normalised ? 1 : boost::math::beta(a, b, pol)) : 0);
    }
 
    if((std::min)(a, b) <= 1)
@@ -888,12 +896,12 @@
          if((a >= (std::min)(T(0.2), b)) || (pow(x, a) <= 0.9))
          {
             if(!invert)
- fract = ibeta_series(a, b, x, T(0), l, normalised, p_derivative, y);
+ fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol);
             else
             {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                invert = false;
- fract = -ibeta_series(a, b, x, fract, l, normalised, p_derivative, y);
+ fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol);
             }
          }
          else
@@ -904,12 +912,12 @@
             if(y >= 0.3)
             {
                if(!invert)
- fract = ibeta_series(a, b, x, T(0), l, normalised, p_derivative, y);
+ fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol);
                else
                {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                   invert = false;
- fract = -ibeta_series(a, b, x, fract, l, normalised, p_derivative, y);
+ fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol);
                }
             }
             else
@@ -924,14 +932,14 @@
                {
                   prefix = 1;
                }
- fract = ibeta_a_step(a, b, x, y, 20, l, normalised, p_derivative);
+ fract = ibeta_a_step(a, b, x, y, 20, pol, normalised, p_derivative);
                if(!invert)
- fract = beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, l, normalised);
+ fract = beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, pol, normalised);
                else
                {
- fract -= (normalised ? 1 : beta_imp(a, b, l));
+ fract -= (normalised ? 1 : boost::math::beta(a, b, pol));
                   invert = false;
- fract = -beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, l, normalised);
+ fract = -beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, pol, normalised);
                }
             }
          }
@@ -942,12 +950,12 @@
          if((b <= 1) || ((x < 0.1) && (pow(b * x, a) <= 0.7)))
          {
             if(!invert)
- fract = ibeta_series(a, b, x, T(0), l, normalised, p_derivative, y);
+ fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol);
             else
             {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                invert = false;
- fract = -ibeta_series(a, b, x, fract, l, normalised, p_derivative, y);
+ fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol);
             }
          }
          else
@@ -959,23 +967,23 @@
             if(y >= 0.3)
             {
                if(!invert)
- fract = ibeta_series(a, b, x, T(0), l, normalised, p_derivative, y);
+ fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol);
                else
                {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                   invert = false;
- fract = -ibeta_series(a, b, x, fract, l, normalised, p_derivative, y);
+ fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol);
                }
             }
             else if(a >= 15)
             {
                if(!invert)
- fract = beta_small_b_large_a_series(a, b, x, y, T(0), T(1), l, normalised);
+ fract = beta_small_b_large_a_series(a, b, x, y, T(0), T(1), pol, normalised);
                else
                {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                   invert = false;
- fract = -beta_small_b_large_a_series(a, b, x, y, fract, T(1), l, normalised);
+ fract = -beta_small_b_large_a_series(a, b, x, y, fract, T(1), pol, normalised);
                }
             }
             else
@@ -990,14 +998,14 @@
                {
                   prefix = 1;
                }
- fract = ibeta_a_step(a, b, x, y, 20, l, normalised, p_derivative);
+ fract = ibeta_a_step(a, b, x, y, 20, pol, normalised, p_derivative);
                if(!invert)
- fract = beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, l, normalised);
+ fract = beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, pol, normalised);
                else
                {
- fract -= (normalised ? 1 : beta_imp(a, b, l));
+ fract -= (normalised ? 1 : boost::math::beta(a, b, pol));
                   invert = false;
- fract = -beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, l, normalised);
+ fract = -beta_small_b_large_a_series(a + 20, b, x, y, fract, prefix, pol, normalised);
                }
             }
          }
@@ -1031,17 +1039,17 @@
             T n = b + k;
             fract = binomial_ccdf(n, k, x, y);
             if(!normalised)
- fract *= boost::math::beta(a, b);
+ fract *= boost::math::beta(a, b, pol);
          }
          else if(b * x <= 0.7)
          {
             if(!invert)
- fract = ibeta_series(a, b, x, T(0), l, normalised, p_derivative, y);
+ fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol);
             else
             {
- fract = -(normalised ? 1 : beta_imp(a, b, l));
+ fract = -(normalised ? 1 : boost::math::beta(a, b, pol));
                invert = false;
- fract = -ibeta_series(a, b, x, fract, l, normalised, p_derivative, y);
+ fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol);
             }
          }
          else if(a > 15)
@@ -1060,8 +1068,8 @@
             {
                prefix = 1;
             }
- fract = ibeta_a_step(bbar, a, y, x, n, l, normalised, static_cast<T*>(0));
- fract = beta_small_b_large_a_series(a, bbar, x, y, fract, T(1), l, normalised);
+ fract = ibeta_a_step(bbar, a, y, x, n, pol, normalised, static_cast<T*>(0));
+ fract = beta_small_b_large_a_series(a, bbar, x, y, fract, T(1), pol, normalised);
             fract /= prefix;
          }
          else if(normalised)
@@ -1076,12 +1084,12 @@
                --n;
                bbar += 1;
             }
- fract = ibeta_a_step(bbar, a, y, x, n, l, normalised, static_cast<T*>(0));
- fract += ibeta_a_step(a, bbar, x, y, 20, l, normalised, static_cast<T*>(0));
+ fract = ibeta_a_step(bbar, a, y, x, n, pol, normalised, static_cast<T*>(0));
+ fract += ibeta_a_step(a, bbar, x, y, 20, pol, normalised, static_cast<T*>(0));
             if(invert)
- fract -= (normalised ? 1 : beta_imp(a, b, l));
+ fract -= (normalised ? 1 : boost::math::beta(a, b, pol));
             //fract = ibeta_series(a+20, bbar, x, fract, l, normalised, p_derivative, y);
- fract = beta_small_b_large_a_series(a+20, bbar, x, y, fract, T(1), l, normalised);
+ fract = beta_small_b_large_a_series(a+20, bbar, x, y, fract, T(1), pol, normalised);
             if(invert)
             {
                fract = -fract;
@@ -1089,16 +1097,16 @@
             }
          }
          else
- fract = ibeta_fraction2(a, b, x, y, l, normalised, p_derivative);
+ fract = ibeta_fraction2(a, b, x, y, pol, normalised, p_derivative);
       }
       else
- fract = ibeta_fraction2(a, b, x, y, l, normalised, p_derivative);
+ fract = ibeta_fraction2(a, b, x, y, pol, normalised, p_derivative);
    }
    if(p_derivative)
    {
       if(*p_derivative < 0)
       {
- *p_derivative = ibeta_power_terms(a, b, x, y, l, true);
+ *p_derivative = ibeta_power_terms(a, b, x, y, lanczos_type(), true, pol);
       }
       T div = y * x;
 
@@ -1115,44 +1123,46 @@
          }
       }
    }
- return invert ? (normalised ? 1 : beta_imp(a, b, l)) - fract : fract;
+ return invert ? (normalised ? 1 : boost::math::beta(a, b, pol)) - fract : fract;
 } // template <class T, class L>T ibeta_imp(T a, T b, T x, const L& l, bool inv, bool normalised)
 
-template <class T, class L>
-inline T ibeta_imp(T a, T b, T x, const L& l, bool inv, bool normalised)
+template <class T, class Policy>
+inline T ibeta_imp(T a, T b, T x, const Policy& pol, bool inv, bool normalised)
 {
- return ibeta_imp(a, b, x, l, inv, normalised, static_cast<T*>(0));
+ return ibeta_imp(a, b, x, pol, inv, normalised, static_cast<T*>(0));
 }
 
-template <class T, class L>
-T ibeta_derivative_imp(T a, T b, T x, const L& l)
+template <class T, class Policy>
+T ibeta_derivative_imp(T a, T b, T x, const Policy& pol)
 {
+ static const char* function = "ibeta_derivative<%1%>(%1%,%1%,%1%)";
    //
    // start with the usual error checks:
    //
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b);
+ policy::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b, pol);
    if((x < 0) || (x > 1))
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x);
+ policy::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol);
    //
    // Now the corner cases:
    //
    if(x == 0)
    {
       return (a > 1) ? 0 :
- (a == 1) ? 1 / boost::math::beta(a, b) : tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ (a == 1) ? 1 / boost::math::beta(a, b, pol) : policy::raise_overflow_error<T>(function, 0, pol);
    }
    else if(x == 1)
    {
       return (b > 1) ? 0 :
- (b == 1) ? 1 / boost::math::beta(a, b) : tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ (b == 1) ? 1 / boost::math::beta(a, b, pol) : policy::raise_overflow_error<T>(function, 0, pol);
    }
    //
    // Now the regular cases:
    //
- T f1 = ibeta_power_terms(a, b, x, 1 - x, l, true);
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
+ T f1 = ibeta_power_terms(a, b, x, 1 - x, lanczos_type(), true, pol);
    T y = (1 - x) * x;
 
    if(f1 == 0)
@@ -1161,14 +1171,39 @@
    if((tools::max_value<T>() * y < f1))
    {
       // overflow:
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
    }
 
    f1 /= y;
 
    return f1;
 }
+//
+// Some forwarding functions that dis-ambiguate the third argument type:
+//
+template <class RT1, class RT2, class Policy>
+inline typename tools::promote_args<RT1, RT2>::type
+ beta(RT1 a, RT2 b, const Policy&, const mpl::true_*)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename tools::promote_args<RT1, RT2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::beta_imp(static_cast<value_type>(a), static_cast<value_type>(b), evaluation_type(), forwarding_policy()), "boost::math::beta<%1%>(%1%,%1%)");
+}
+template <class RT1, class RT2, class RT3>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ beta(RT1 a, RT2 b, RT3 x, const mpl::false_*)
+{
+ return boost::math::beta(a, b, x, policy::policy<>());
+}
 } // namespace detail
 
 //
@@ -1176,70 +1211,130 @@
 // which Lanczos approximation to use
 // and forward to the implementation functions:
 //
+template <class RT1, class RT2, class A>
+inline typename tools::promote_args<RT1, RT2, A>::type
+ beta(RT1 a, RT2 b, A arg)
+{
+ typedef typename policy::is_policy<A>::type tag;
+ return boost::math::detail::beta(a, b, arg, static_cast<tag*>(0));
+}
+
 template <class RT1, class RT2>
 inline typename tools::promote_args<RT1, RT2>::type
    beta(RT1 a, RT2 b)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename tools::promote_args<RT1, RT2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::beta_imp(static_cast<value_type>(a), static_cast<value_type>(b), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ return boost::math::beta(a, b, policy::policy<>());
 }
 
-template <class RT1, class RT2, class RT3>
+template <class RT1, class RT2, class RT3, class Policy>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
- beta(RT1 a, RT2 b, RT3 x)
+ beta(RT1 a, RT2 b, RT3 x, const Policy&)
 {
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), evaluation_type(), false, false), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), false, false), "boost::math::beta<%1%>(%1%,%1%,%1%)");
 }
 
+template <class RT1, class RT2, class RT3, class Policy>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ betac(RT1 a, RT2 b, RT3 x, const Policy&)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), true, false), "boost::math::betac<%1%>(%1%,%1%,%1%)");
+}
 template <class RT1, class RT2, class RT3>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
    betac(RT1 a, RT2 b, RT3 x)
 {
+ return boost::math::betac(a, b, x, policy::policy<>());
+}
+
+template <class RT1, class RT2, class RT3, class Policy>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta(RT1 a, RT2 b, RT3 x, const Policy&)
+{
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), evaluation_type(), true, false), BOOST_CURRENT_FUNCTION);
-}
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), false, true), "boost::math::ibeta<%1%>(%1%,%1%,%1%)");
+}
 template <class RT1, class RT2, class RT3>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
    ibeta(RT1 a, RT2 b, RT3 x)
 {
+ return boost::math::ibeta(a, b, x, policy::policy<>());
+}
+
+template <class RT1, class RT2, class RT3, class Policy>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac(RT1 a, RT2 b, RT3 x, const Policy&)
+{
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), evaluation_type(), false, true), BOOST_CURRENT_FUNCTION);
-}
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), true, true), "boost::math::ibetac<%1%>(%1%,%1%,%1%)");
+}
 template <class RT1, class RT2, class RT3>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
    ibetac(RT1 a, RT2 b, RT3 x)
 {
+ return boost::math::ibetac(a, b, x, policy::policy<>());
+}
+
+template <class RT1, class RT2, class RT3, class Policy>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_derivative(RT1 a, RT2 b, RT3 x, const Policy&)
+{
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), evaluation_type(), true, true), BOOST_CURRENT_FUNCTION);
-}
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy()), "boost::math::ibeta_derivative<%1%>(%1%,%1%,%1%)");
+}
 template <class RT1, class RT2, class RT3>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
    ibeta_derivative(RT1 a, RT2 b, RT3 x)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::ibeta_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ return boost::math::ibeta_derivative(a, b, x, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/binomial.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/binomial.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/binomial.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,19 +8,20 @@
 
 #include <boost/math/special_functions/factorials.hpp>
 #include <boost/math/special_functions/beta.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 namespace boost{ namespace math{
 
-template <class T>
-T binomial_coefficient(unsigned n, unsigned k)
+template <class T, class Policy>
+T binomial_coefficient(unsigned n, unsigned k, const Policy& pol)
 {
    using namespace std;
+ static const char* function = "boost::math::binomial_coefficient<%1%>(unsigned, unsigned)";
    if(k > n)
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(
+ function,
          "The binomial coefficient is undefined for k > n, but got k = %1%.",
- k);
+ k, pol);
    T result;
    if((k == 0) || (k == n))
       return 1;
@@ -38,11 +39,11 @@
    {
       // Use the beta function:
       if(k < n - k)
- result = k * beta(static_cast<T>(k), static_cast<T>(n-k+1));
+ result = k * beta(static_cast<T>(k), static_cast<T>(n-k+1), pol);
       else
- result = (n - k) * beta(static_cast<T>(k+1), static_cast<T>(n-k));
+ result = (n - k) * beta(static_cast<T>(k+1), static_cast<T>(n-k), pol);
       if(result == 0)
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
       result = 1 / result;
    }
    // convert to nearest integer:
@@ -54,9 +55,15 @@
 // we'll promote to double:
 //
 template <>
-inline float binomial_coefficient<float>(unsigned n, unsigned k)
+inline float binomial_coefficient<float, policy::policy<> >(unsigned n, unsigned k, const policy::policy<>& pol)
+{
+ return policy::checked_narrowing_cast<float, policy::policy<> >(binomial_coefficient<double>(n, k, pol), "boost::math::binomial_coefficient<%1%>(unsigned,unsigned)");
+}
+
+template <class T>
+inline T binomial_coefficient(unsigned n, unsigned k)
 {
- return tools::checked_narrowing_cast<float>(binomial_coefficient<double>(n, k), BOOST_CURRENT_FUNCTION);
+ return binomial_coefficient<T>(n, k, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/cbrt.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/cbrt.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/cbrt.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -27,8 +27,8 @@
                  T a;
         };
 
-template <class T>
-T cbrt_imp(T z)
+template <class T, class Policy>
+T cbrt_imp(T z, const Policy&)
 {
    using namespace std;
    int exp, sign(1);
@@ -44,17 +44,23 @@
    T min = static_cast<T>(ldexp(0.5, exp/3));
    T max = static_cast<T>(ldexp(2.0, exp/3));
    T guess = static_cast<T>(ldexp(1.0, exp/3));
- int digits = (tools::digits<T>()) / 2;
+ int digits = (policy::digits<T, Policy>()) / 2;
    return sign * tools::halley_iterate(detail::cbrt_functor<T>(z), guess, min, max, digits);
 }
 
 } // namespace detail
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type cbrt(T z, const Policy& pol)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ return detail::cbrt_imp(result_type(z), pol);
+}
+
 template <class T>
 inline typename tools::promote_args<T>::type cbrt(T z)
 {
- typedef typename tools::promote_args<T>::type result_type;
- return detail::cbrt_imp(result_type(z));
+ return cbrt(z, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/cos_pi.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/cos_pi.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/cos_pi.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -40,6 +40,12 @@
    return invert ? -rem : rem;
 }
 
+template <class T, class Policy>
+inline T cos_pi(T x, const Policy&)
+{
+ return cos_pi(x);
+}
+
 } // namespace math
 } // namespace boost
 #endif

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/math/special_functions/sin_pi.hpp>
 #include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/tools/config.hpp>
 
 // Modified Bessel functions of the first and second kind of fractional order
@@ -20,8 +20,8 @@
 
 // Calculate K(v, x) and K(v+1, x) by method analogous to
 // Temme, Journal of Computational Physics, vol 21, 343 (1976)
-template <typename T>
-int temme_ik(T v, T x, T* K, T* K1)
+template <typename T, typename Policy>
+int temme_ik(T v, T x, T* K, T* K1, const Policy& pol)
 {
     T f, h, p, q, coef, sum, sum1, tolerance;
     T a, b, c, d, sigma, gamma1, gamma2;
@@ -37,8 +37,8 @@
     BOOST_ASSERT(abs(x) <= 2);
     BOOST_ASSERT(abs(v) <= 0.5f);
 
- T gp = tgamma1pm1(v);
- T gm = tgamma1pm1(-v);
+ T gp = tgamma1pm1(v, pol);
+ T gm = tgamma1pm1(-v, pol);
 
     a = log(x / 2);
     b = exp(v * a);
@@ -76,7 +76,7 @@
            break;
         }
     }
- check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%)", k, pol);
 
     *K = sum;
     *K1 = 2 * sum1 / x;
@@ -86,8 +86,8 @@
 
 // Evaluate continued fraction fv = I_(v+1) / I_v, derived from
 // Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73
-template <typename T>
-int CF1_ik(T v, T x, T* fv)
+template <typename T, typename Policy>
+int CF1_ik(T v, T x, T* fv, const Policy& pol)
 {
     T C, D, f, a, b, delta, tiny, tolerance;
     int k;
@@ -119,7 +119,7 @@
            break;
         }
     }
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%)", k, pol);
 
     *fv = f;
 
@@ -129,8 +129,8 @@
 // Calculate K(v, x) and K(v+1, x) by evaluating continued fraction
 // z1 / z0 = U(v+1.5, 2v+1, 2x) / U(v+0.5, 2v+1, 2x), see
 // Thompson and Barnett, Computer Physics Communications, vol 47, 245 (1987)
-template <typename T>
-int CF2_ik(T v, T x, T* Kv, T* Kv1)
+template <typename T, typename Policy>
+int CF2_ik(T v, T x, T* Kv, T* Kv1, const Policy& pol)
 {
     using namespace std;
     using namespace boost::math::constants;
@@ -177,7 +177,7 @@
            break;
         }
     }
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%)", k, pol);
 
     *Kv = sqrt(pi<T>() / (2 * x)) * exp(-x) / S;
     *Kv1 = *Kv * (0.5f + v + x + (v * v - 0.25f) * f) / x;
@@ -192,8 +192,8 @@
 
 // Compute I(v, x) and K(v, x) simultaneously by Temme's method, see
 // Temme, Journal of Computational Physics, vol 19, 324 (1975)
-template <typename T>
-int bessel_ik(T v, T x, T* I, T* K, int kind = need_i | need_k)
+template <typename T, typename Policy>
+int bessel_ik(T v, T x, T* I, T* K, int kind, const Policy& pol)
 {
     // Kv1 = K_(v+1), fv = I_(v+1) / I_v
     // Ku1 = K_(u+1), fu = I_(u+1) / I_u
@@ -206,6 +206,8 @@
     using namespace boost::math::tools;
     using namespace boost::math::constants;
 
+ static const char* function = "boost::math::bessel_ik<%1%>(%1%,%1%)";
+
     if (v < 0)
     {
         reflect = true;
@@ -217,8 +219,8 @@
 
     if (x < 0)
     {
- *I = *K = domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1% but real argument x must be non-negative, complex number result not supported.", x);
+ *I = *K = policy::raise_domain_error<T>(function,
+ "Got x = %1% but real argument x must be non-negative, complex number result not supported.", x, pol);
         return 1;
     }
     if (x == 0)
@@ -226,7 +228,7 @@
        Iv = (v == 0) ? static_cast<T>(1) : static_cast<T>(0);
        if(kind & need_k)
        {
- Kv = tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ Kv = policy::raise_overflow_error<T>(function, 0, pol);
        }
        else
        {
@@ -236,9 +238,9 @@
        if(reflect && (kind & need_i))
        {
            T z = (u + n % 2);
- Iv = sin_pi(z) == 0 ?
+ Iv = sin_pi(z, pol) == 0 ?
                Iv :
- tools::overflow_error<T>(BOOST_CURRENT_FUNCTION); // reflection formula
+ policy::raise_overflow_error<T>(function, 0, pol); // reflection formula
        }
 
        *I = Iv;
@@ -250,11 +252,11 @@
     W = 1 / x; // Wronskian
     if (x <= 2) // x in (0, 2]
     {
- temme_ik(u, x, &Ku, &Ku1); // Temme series
+ temme_ik(u, x, &Ku, &Ku1, pol); // Temme series
     }
     else // x in (2, \infty)
     {
- CF2_ik(u, x, &Ku, &Ku1); // continued fraction CF2_ik
+ CF2_ik(u, x, &Ku, &Ku1, pol); // continued fraction CF2_ik
     }
     prev = Ku;
     current = Ku1;
@@ -279,11 +281,11 @@
           // x case instead. Note that the asymptotic expansion
           // isn't very accurate - so it's deliberately very hard
           // to get here - probably we're going to overflow:
- Iv = asymptotic_bessel_i_large_x(v, x);
+ Iv = asymptotic_bessel_i_large_x(v, x, pol);
        }
        else
        {
- CF1_ik(v, x, &fv); // continued fraction CF1_ik
+ CF1_ik(v, x, &fv, pol); // continued fraction CF1_ik
           Iv = W / (Kv * fv + Kv1); // Wronskian relation
        }
     }

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jn.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jn.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jn.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -17,8 +17,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_jn(int n, T x)
+template <typename T, typename Policy>
+T bessel_jn(int n, T x, const Policy& pol)
 {
     T value(0), factor, current, prev, next;
 
@@ -62,7 +62,7 @@
     {
         T fn; int s; // fn = J_(n+1) / J_n
         // |x| <= n, fast convergence for continued fraction CF1
- boost::math::detail::CF1_jy(static_cast<T>(n), x, &fn, &s);
+ boost::math::detail::CF1_jy(static_cast<T>(n), x, &fn, &s, pol);
         // tiny initial value to prevent overflow
         T init = sqrt(tools::min_value<T>());
         prev = fn * init;

Deleted: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jv.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_jv.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,122 +0,0 @@
-// Copyright (c) 2006 Xiaogang Zhang
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_MATH_BESSEL_JV_HPP
-#define BOOST_MATH_BESSEL_JV_HPP
-
-#include <boost/math/special_functions/bessel_jn.hpp>
-#include <boost/math/special_functions/bessel_jy.hpp>
-#include <boost/math/constants/constants.hpp>
-
-// Bessel and Spherical Bessel functions of the first kind
-
-namespace boost { namespace math {
-
-// Bessel function of the first kind of any order
-template <typename T>
-inline T bessel_jv(T v, T x)
-{
- int n = static_cast<int>(v);
- if (v == n)
- {
- return bessel_jn(n, x); // v is integer
- }
- else
- {
- T J, Y;
- bessel_jy(v, x, &J, &Y);
- return J;
- }
-}
-
-// Spherical Bessel function of the first kind of non-negative order
-template <typename T>
-inline T bessel_sjv(unsigned n, T x)
-{
- using namespace std;
- using namespace boost::math::constants;
-
- T v = n + 0.5L;
- if (x == 0)
- {
- return (n == 0) ? static_cast<T>(1) : static_cast<T>(0);
- }
- else
- {
- return sqrt(0.5L * pi<T>() / x) * bessel_jv(v, x);
- }
-}
-
-// -------------------- TR1 functions --------------------
-
-inline float cyl_bessel_jf(float nu, float x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_jf(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_jv<float>(nu, x);
-}
-
-inline double cyl_bessel_j(double nu, double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_j(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_jv<double>(nu, x);
-}
-
-inline long double cyl_bessel_jl(long double nu, long double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_jl(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_jv<long double>(nu, x);
-}
-
-inline float sph_besself(unsigned n, float x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_besself(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_sjv<float>(n, x);
-}
-
-inline double sph_bessel(unsigned n, double x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_bessel(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_sjv<double>(n, x);
-}
-
-inline long double sph_bessell(unsigned n, long double x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_bessell(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_sjv<long double>(n, x);
-}
-
-}} // namespaces
-
-#endif // BOOST_MATH_BESSEL_JV_HPP

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -15,7 +15,7 @@
 #include <boost/math/special_functions/detail/simple_complex.hpp>
 #include <boost/math/special_functions/detail/bessel_jy_asym.hpp>
 #include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <complex>
@@ -28,8 +28,8 @@
 
 // Calculate Y(v, x) and Y(v+1, x) by Temme's method, see
 // Temme, Journal of Computational Physics, vol 21, 343 (1976)
-template <typename T>
-int temme_jy(T v, T x, T* Y, T* Y1)
+template <typename T, typename Policy>
+int temme_jy(T v, T x, T* Y, T* Y1, const Policy& pol)
 {
     T g, h, p, q, f, coef, sum, sum1, tolerance;
     T a, d, e, sigma;
@@ -41,10 +41,10 @@
 
     BOOST_ASSERT(fabs(v) <= 0.5f); // precondition for using this routine
 
- T gp = tgamma1pm1(v);
- T gm = tgamma1pm1(-v);
- T spv = sin_pi(v);
- T spv2 = sin_pi(v/2);
+ T gp = tgamma1pm1(v, pol);
+ T gm = tgamma1pm1(-v, pol);
+ T spv = sin_pi(v, pol);
+ T spv2 = sin_pi(v/2, pol);
     T xp = pow(x/2, v);
 
     a = log(x / 2);
@@ -88,7 +88,7 @@
            break;
         }
     }
- check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%)", k, pol);
     *Y = -sum;
     *Y1 = -2 * sum1 / x;
 
@@ -97,8 +97,8 @@
 
 // Evaluate continued fraction fv = J_(v+1) / J_v, see
 // Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73
-template <typename T>
-int CF1_jy(T v, T x, T* fv, int* sign)
+template <typename T, typename Policy>
+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;
@@ -129,7 +129,7 @@
         if (abs(delta - 1.0L) < tolerance)
         { break; }
     }
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k / 100);
+ policy::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%)", k / 100, pol);
     *fv = -f;
     *sign = s; // sign of denominator
 
@@ -145,8 +145,8 @@
 
 // Evaluate continued fraction p + iq = (J' + iY') / (J + iY), see
 // Press et al, Numerical Recipes in C, 2nd edition, 1992
-template <typename T>
-int CF2_jy(T v, T x, T* p, T* q)
+template <typename T, typename Policy>
+int CF2_jy(T v, T x, T* p, T* q, const Policy& pol)
 {
     using namespace std;
 
@@ -183,7 +183,7 @@
         f *= delta;
         if (abs(delta - one) < tolerance) { break; }
     }
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%)", k, pol);
     *p = real(f);
     *q = imag(f);
 
@@ -197,8 +197,8 @@
 
 // Compute J(v, x) and Y(v, x) simultaneously by Steed's method, see
 // Barnett et al, Computer Physics Communications, vol 8, 377 (1974)
-template <typename T>
-int bessel_jy(T v, T x, T* J, T* Y, int kind = need_j|need_y)
+template <typename T, typename Policy>
+int bessel_jy(T v, T x, T* J, T* Y, int kind, const Policy& pol)
 {
     BOOST_ASSERT(x >= 0);
 
@@ -207,6 +207,8 @@
     bool reflect = false;
     int n, k, s;
 
+ static const char* function = "boost::math::bessel_jy<%1%>(%1%,%1%)";
+
     using namespace std;
     using namespace boost::math::tools;
     using namespace boost::math::constants;
@@ -222,8 +224,8 @@
 
     if (x == 0)
     {
- *J = *Y = tools::overflow_error<T>(
- BOOST_CURRENT_FUNCTION);
+ *J = *Y = policy::raise_overflow_error<T>(
+ function, 0, pol);
        return 1;
     }
 
@@ -231,7 +233,7 @@
     W = T(2) / (x * pi<T>()); // Wronskian
     if (x <= 2) // x in (0, 2]
     {
- if(temme_jy(u, x, &Yu, &Yu1)) // Temme series
+ if(temme_jy(u, x, &Yu, &Yu1, pol)) // Temme series
         {
            // domain error:
            *J = *Y = Yu;
@@ -249,7 +251,7 @@
         Yv1 = current;
         if(kind&need_j)
         {
- CF1_jy(v, x, &fv, &s); // continued fraction CF1_jy
+ CF1_jy(v, x, &fv, &s, pol); // continued fraction CF1_jy
           Jv = W / (Yv * fv - Yv1); // Wronskian relation
         }
         else
@@ -259,7 +261,7 @@
     {
         // Get Y(u, x):
         // define tag type that will dispatch to right limits:
- typedef typename bessel_asymptotic_tag<T>::type tag_type;
+ typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type;
 
         T lim;
         switch(kind)
@@ -294,7 +296,7 @@
         }
         else
         {
- CF1_jy(v, x, &fv, &s);
+ CF1_jy(v, x, &fv, &s, pol);
            // tiny initial value to prevent overflow
            T init = sqrt(tools::min_value<T>());
            prev = fv * s * init;
@@ -308,7 +310,7 @@
            T ratio = (s * init) / current; // scaling ratio
            // can also call CF1_jy() to get fu, not much difference in precision
            fu = prev / current;
- CF2_jy(u, x, &p, &q); // continued fraction CF2_jy
+ CF2_jy(u, x, &p, &q, pol); // continued fraction CF2_jy
            T t = u / x - fu; // t = J'/J
            gamma = (p - t) / q;
            Ju = sign(current) * sqrt(W / (q + gamma * (p - t)));
@@ -338,8 +340,8 @@
     if (reflect)
     {
         T z = (u + n % 2);
- *J = cos_pi(z) * Jv - sin_pi(z) * Yv; // reflection formula
- *Y = sin_pi(z) * Jv + cos_pi(z) * Yv;
+ *J = cos_pi(z, pol) * Jv - sin_pi(z, pol) * Yv; // reflection formula
+ *Y = sin_pi(z, pol) * Jv + cos_pi(z, pol) * Yv;
     }
     else
     {

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -178,18 +178,20 @@
    return 1245243 /*3128000*/;
 }
 
-template <class T>
+template <class T, class Policy>
 struct bessel_asymptotic_tag
 {
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::digits == 0
- || std::numeric_limits<T>::digits > 113),
+ typedef typename policy::precision<T, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::or_<
+ mpl::equal_to<precision_type, mpl::int_<0> >,
+ mpl::greater<precision_type, mpl::int_<113> > >,
       mpl::int_<0>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits > 64),
+ typename mpl::if_<
+ mpl::greater<precision_type, mpl::int_<64> >,
          mpl::int_<113>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits > 53),
+ typename mpl::if_<
+ mpl::greater<precision_type, mpl::int_<53> >,
             mpl::int_<64>,
             mpl::int_<53>
>::type
@@ -227,14 +229,14 @@
    return v2 * 39154 /*85700*/;
 }
 
-template <class T>
-void temme_asyptotic_y_small_x(T v, T x, T* Y, T* Y1)
+template <class T, class Policy>
+void temme_asyptotic_y_small_x(T v, T x, T* Y, T* Y1, const Policy& pol)
 {
    T c = 1;
- T p = (v / sin_pi(v)) * pow(x / 2, -v) / tgamma(1 - v);
- T q = (v / sin_pi(v)) * pow(x / 2, v) / tgamma(1 + v);
+ T p = (v / sin_pi(v, pol)) * pow(x / 2, -v) / tgamma(1 - v, pol);
+ T q = (v / sin_pi(v, pol)) * pow(x / 2, v) / tgamma(1 + v, pol);
    T f = (p - q) / v;
- T g_prefix = sin_pi(v / 2);
+ T g_prefix = sin_pi(v / 2, pol);
    g_prefix *= g_prefix * 2 / v;
    T g = f + g_prefix * q;
    T h = p;
@@ -248,7 +250,7 @@
       p /= k - v;
       q /= k + v;
       c *= c_mult / k;
- T c1 = pow(-x * x / 4, k) / factorial<T>(k);
+ T c1 = pow(-x * x / 4, k) / factorial<T>(k, pol);
       g = f + g_prefix * q;
       h = -k * g + p;
       y += c * g;
@@ -261,8 +263,8 @@
    *Y1 = (-2 / x) * y1;
 }
 
-template <class T>
-T asymptotic_bessel_i_large_x(T v, T x)
+template <class T, class Policy>
+T asymptotic_bessel_i_large_x(T v, T x, const Policy& pol)
 {
    using namespace std; // ADL of std names
    T s = 1;
@@ -287,7 +289,7 @@
    s = e * (e * s / sqrt(2 * x * constants::pi<T>()));
 
    return (boost::math::isfinite)(s) ?
- s : tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ s : policy::raise_overflow_error<T>("boost::math::asymptotic_bessel_i_large_x<%1%>(%1%,%1%)", 0, pol);
 }
 
 }}} // namespaces

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k0.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k0.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k0.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -7,7 +7,7 @@
 #define BOOST_MATH_BESSEL_K0_HPP
 
 #include <boost/math/tools/rational.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/assert.hpp>
 
 // Modified Bessel function of the second kind of order zero
@@ -16,8 +16,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_k0(T x)
+template <typename T, typename Policy>
+T bessel_k0(T x, const Policy& pol)
 {
     static const T P1[] = {
          static_cast<T>(2.4708152720399552679e+03L),
@@ -75,14 +75,16 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::bessel_k0<%1%>(%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but argument x must be non-negative, complex number result not supported", x);
+ return policy::raise_domain_error<T>(function,
+ "Got x = %1%, but argument x must be non-negative, complex number result not supported", x, pol);
     }
     if (x == 0)
     {
- return overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
     }
     if (x <= 1) // x in (0, 1]
     {

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_k1.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -7,7 +7,7 @@
 #define BOOST_MATH_BESSEL_K1_HPP
 
 #include <boost/math/tools/rational.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/assert.hpp>
 
 // Modified Bessel function of the second kind of order one
@@ -16,8 +16,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_k1(T x)
+template <typename T, typename Policy>
+T bessel_k1(T x, const Policy& pol)
 {
     static const T P1[] = {
         static_cast<T>(-2.2149374878243304548e+06L),
@@ -77,14 +77,16 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::bessel_k1<%1%>(%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x);
+ return policy::raise_domain_error<T>(function,
+ "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x, pol);
     }
     if (x == 0)
     {
- return overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
     }
     if (x <= 1) // x in (0, 1]
     {

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kn.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kn.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kn.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,45 +8,47 @@
 
 #include <boost/math/special_functions/detail/bessel_k0.hpp>
 #include <boost/math/special_functions/detail/bessel_k1.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Modified Bessel function of the second kind of integer order
 // K_n(z) is the dominant solution, forward recurrence always OK (though unstable)
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_kn(int n, T x)
+template <typename T, typename Policy>
+T bessel_kn(int n, T x, const Policy& pol)
 {
     T value, current, prev;
 
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::bessel_kn<%1%>(%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x);
+ return policy::raise_domain_error<T>(function,
+ "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x, pol);
     }
     if (x == 0)
     {
- return overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
     }
 
     if (n == 0)
     {
- return bessel_k0(x);
+ return bessel_k0(x, pol);
     }
     if (n == 1)
     {
- return bessel_k1(x);
+ return bessel_k1(x, pol);
     }
     if (n < 0)
     {
         n = -n; // K_{-n}(z) = K_n(z)
     }
 
- prev = bessel_k0(x);
- current = bessel_k1(x);
+ prev = bessel_k0(x, pol);
+ current = bessel_k1(x, pol);
     for (int k = 1; k < n; k++) // n >= 2
     {
         value = 2 * k * current / x + prev;

Deleted: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kv.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_kv.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,91 +0,0 @@
-// Copyright (c) 2006 Xiaogang Zhang
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_MATH_BESSEL_KV_HPP
-#define BOOST_MATH_BESSEL_KV_HPP
-
-#include <boost/math/special_functions/bessel_kn.hpp>
-#include <boost/math/special_functions/bessel_ik.hpp>
-#include <boost/math/constants/constants.hpp>
-
-// Modified Bessel and Spherical Bessel functions of the second kind
-
-namespace boost { namespace math {
-
-// Modified Bessel function of the second kind of any order
-template <typename T>
-inline T bessel_kv(T v, T x)
-{
- int n = static_cast<int>(v);
- if (v == n)
- {
- return bessel_kn(n, x); // v is integer
- }
- else
- {
- T I, K;
- bessel_ik(v, x, &I, &K);
- return K;
- }
-}
-
-// Modified Spherical Bessel function of the second kind of non-negative order
-template <typename T>
-inline T bessel_skv(unsigned n, T x)
-{
- using namespace std;
- using namespace boost::math::tools;
- using namespace boost::math::constants;
-
- T v = n + 0.5L;
- if (x == 0)
- {
- return overflow_error<T>("boost::math::bessel_skv(n, x)",
- "infinity occurred but not supported");
- }
- else
- {
- return sqrt(0.5L * pi<T>() / x) * bessel_kv(v, x);
- }
-}
-
-// -------------------- TR1 functions --------------------
-
-inline float cyl_bessel_kf(float nu, float x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_kf(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_kv<float>(nu, x);
-}
-
-inline double cyl_bessel_k(double nu, double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_k(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_kv<double>(nu, x);
-}
-
-inline long double cyl_bessel_kl(long double nu, long double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_bessel_kl(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_kv<long double>(nu, x);
-}
-
-}} // namespaces
-
-#endif // BOOST_MATH_BESSEL_KV_HPP

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y0.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y0.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y0.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 #include <boost/math/special_functions/detail/bessel_j0.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/tools/rational.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/assert.hpp>
 
 // Bessel function of the second kind of order zero
@@ -18,8 +18,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_y0(T x)
+template <typename T, typename Policy>
+T bessel_y0(T x, const Policy& pol)
 {
     static const T P1[] = {
          static_cast<T>(1.0723538782003176831e+11L),
@@ -123,14 +123,16 @@
     using namespace boost::math::tools;
     using namespace boost::math::constants;
 
+ static const char* function = "boost::math::bessel_y0<%1%>(%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1% but x must be non-negative, complex result not supported.", x);
+ return policy::raise_domain_error<T>(function,
+ "Got x = %1% but x must be non-negative, complex result not supported.", x, pol);
     }
     if (x == 0)
     {
- return -overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
     }
     if (x <= 3) // x in (0, 3]
     {

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_y1.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 #include <boost/math/special_functions/detail/bessel_j1.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/tools/rational.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/assert.hpp>
 
 // Bessel function of the second kind of order one
@@ -18,8 +18,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_y1(T x)
+template <typename T, typename Policy>
+T bessel_y1(T x, const Policy& pol)
 {
     static const T P1[] = {
          static_cast<T>(4.0535726612579544093e+13L),
@@ -112,8 +112,8 @@
 
     if (x <= 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x == %1%, but x must be > 0, complex result not supported.", x);
+ return policy::raise_domain_error<T>("bost::math::bessel_y1<%1%>(%1%,%1%)",
+ "Got x == %1%, but x must be > 0, complex result not supported.", x, pol);
     }
     if (x <= 4) // x in (0, 4]
     {

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yn.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yn.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yn.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,37 +8,39 @@
 
 #include <boost/math/special_functions/detail/bessel_y0.hpp>
 #include <boost/math/special_functions/detail/bessel_y1.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Bessel function of the second kind of integer order
 // Y_n(z) is the dominant solution, forward recurrence always OK (though unstable)
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T bessel_yn(int n, T x)
+template <typename T, typename Policy>
+T bessel_yn(int n, T x, const Policy& pol)
 {
     T value, factor, current, prev;
 
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::bessel_yn<%1%>(%1%,%1%)";
+
     if ((x == 0) && (n == 0))
     {
- return -overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(function, 0, pol);
     }
     if (x <= 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got x = %1%, but x must be > 0, complex result not supported.", x);
+ return policy::raise_domain_error<T>(function,
+ "Got x = %1%, but x must be > 0, complex result not supported.", x, pol);
     }
 
     if (n == 0)
     {
- return bessel_y0(x);
+ return bessel_y0(x, pol);
     }
     if (n == 1)
     {
- return bessel_y1(x);
+ return bessel_y1(x, pol);
     }
     if (n < 0)
     {
@@ -50,8 +52,8 @@
         factor = 1;
     }
 
- prev = bessel_y0(x);
- current = bessel_y1(x);
+ prev = bessel_y0(x, pol);
+ current = bessel_y1(x, pol);
     for (int k = 1; k < n; k++) // n >= 2
     {
         value = 2 * k * current / x - prev;

Deleted: sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yv.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/bessel_yv.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,125 +0,0 @@
-// Copyright (c) 2006 Xiaogang Zhang
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_MATH_BESSEL_YV_HPP
-#define BOOST_MATH_BESSEL_YV_HPP
-
-#include <boost/math/special_functions/bessel_yn.hpp>
-#include <boost/math/special_functions/bessel_jy.hpp>
-#include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
-
-// Bessel and Spherical Bessel functions of the second kind
-
-namespace boost { namespace math {
-
-// Bessel function of the second kind of any order
-template <typename T>
-inline T bessel_yv(T v, T x)
-{
- int n = static_cast<int>(v);
- if (v == n)
- {
- return bessel_yn(n, x); // v is integer
- }
- else
- {
- T J, Y;
- bessel_jy(v, x, &J, &Y);
- return Y;
- }
-}
-
-// Spherical Bessel function of the second kind of non-negative order
-template <typename T>
-inline T bessel_syv(unsigned n, T x)
-{
- using namespace std;
- using namespace boost::math::tools;
- using namespace boost::math::constants;
-
- T v = n + 0.5L;
- if (x == 0)
- {
- return -overflow_error<T>("boost::math::bessel_syv(n, x)",
- "infinity occurred but not supported");
- }
- else
- {
- return sqrt(0.5L * pi<T>() / x) * bessel_yv(v, x);
- }
-}
-
-// -------------------- TR1 functions --------------------
-
-inline float cyl_neumannf(float nu, float x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_neumannf(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_yv<float>(nu, x);
-}
-
-inline double cyl_neumann(double nu, double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_neumann(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_yv<double>(nu, x);
-}
-
-inline long double cyl_neumannl(long double nu, long double x)
-{
- if (nu >= 128)
- {
- std::cout << "Warning: cyl_neumannl(nu, x), nu >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_yv<long double>(nu, x);
-}
-
-inline float sph_neumannf(unsigned n, float x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_neumannf(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_syv<float>(n, x);
-}
-
-inline double sph_neumann(unsigned n, double x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_neumann(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_syv<double>(n, x);
-}
-
-inline long double sph_neumannl(unsigned n, long double x)
-{
- if (n >= 128)
- {
- std::cout << "Warning: sph_neumannl(n, x), n >= 128, "
- << "result is implementation defined according to C++ TR1"
- << std::endl;
- }
- return bessel_syv<long double>(n, x);
-}
-
-}} // namespaces
-
-#endif // BOOST_MATH_BESSEL_YV_HPP

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/erf_inv.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/erf_inv.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/erf_inv.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,8 +13,8 @@
 // The inverse erf and erfc functions share a common implementation,
 // this version is for 80-bit long double's and smaller:
 //
-template <class T>
-T erf_inv_imp(const T& p, const T& q, const boost::mpl::int_<64>*)
+template <class T, class Policy>
+T erf_inv_imp(const T& p, const T& q, const Policy&, const boost::mpl::int_<64>*)
 {
    using namespace std; // for ADL of std names.
 
@@ -270,7 +270,7 @@
    return result;
 }
 
-template <class T>
+template <class T, class Policy>
 struct erf_roots
 {
    std::tr1::tuple<T,T,T> operator()(const T& guess)
@@ -278,7 +278,7 @@
       using namespace std;
       T derivative = sign * (2 / sqrt(constants::pi<T>())) * exp(-(guess * guess));
       T derivative2 = -2 * guess * derivative;
- return std::tr1::make_tuple(((sign > 0) ? boost::math::erf(guess) : boost::math::erfc(guess)) - target, derivative, derivative2);
+ return std::tr1::make_tuple(((sign > 0) ? boost::math::erf(guess, Policy()) : boost::math::erfc(guess, Policy())) - target, derivative, derivative2);
    }
    erf_roots(T z, int s) : target(z), sign(s) {}
 private:
@@ -286,27 +286,27 @@
    int sign;
 };
 
-template <class T>
-T erf_inv_imp(const T& p, const T& q, const boost::mpl::int_<0>*)
+template <class T, class Policy>
+T erf_inv_imp(const T& p, const T& q, const Policy& pol, const boost::mpl::int_<0>*)
 {
    //
    // Generic version, get a guess that's accurate to 64-bits (10^-19)
    //
- T guess = erf_inv_imp(p, q, static_cast<mpl::int_<64> const*>(0));
+ T guess = erf_inv_imp(p, q, pol, static_cast<mpl::int_<64> const*>(0));
    T result;
    //
    // If T has more bit's than 64 in it's mantissa then we need to iterate,
    // otherwise we can just return the result:
    //
- if(tools::digits<T>() > 64)
+ if(policy::digits<T, Policy>() > 64)
    {
       if(p <= 0.5)
       {
- result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type>(p, 1), guess, static_cast<T>(0), tools::max_value<T>(), (tools::digits<T>() * 2) / 3);
+ result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type, Policy>(p, 1), guess, static_cast<T>(0), tools::max_value<T>(), (policy::digits<T, Policy>() * 2) / 3);
       }
       else
       {
- result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type>(q, -1), guess, static_cast<T>(0), tools::max_value<T>(), (tools::digits<T>() * 2) / 3);
+ result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type, Policy>(q, -1), guess, static_cast<T>(0), tools::max_value<T>(), (policy::digits<T, Policy>() * 2) / 3);
       }
    }
    else
@@ -318,19 +318,20 @@
 
 } // namespace detail
 
-template <class T>
-typename tools::promote_args<T>::type erfc_inv(T z)
+template <class T, class Policy>
+typename tools::promote_args<T>::type erfc_inv(T z, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
    //
    // Begin by testing for domain errors, and other special cases:
    //
+ static const char* function = "boost::math::erfc_inv<%1%>(%1%, %1%)";
    if((z < 0) || (z > 2))
- tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "Argument outside range [0,2] in inverse erfc function (got p=%1%).", z);
+ policy::raise_domain_error<result_type>(function, "Argument outside range [0,2] in inverse erfc function (got p=%1%).", z, pol);
    if(z == 0)
- return tools::overflow_error<result_type>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<result_type>(function, 0, pol);
    if(z == 2)
- return -tools::overflow_error<result_type>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<result_type>(function, 0, pol);
    //
    // Normalise the input, so it's in the range [0,1], we will
    // negate the result if z is outside that range. This is a simple
@@ -353,38 +354,45 @@
    // A bit of meta-programming to figure out which implementation
    // to use, based on the number of bits in the mantissa of T:
    //
- typedef typename mpl::if_c<
- std::numeric_limits<result_type>::is_specialized
- &&
- (std::numeric_limits<result_type>::digits <= 64),
- mpl::int_<64>,
- mpl::int_<0>
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::or_<mpl::less_equal<precision_type, mpl::int_<0> >, mpl::greater<precision_type, mpl::int_<64> > >,
+ mpl::int_<0>,
+ mpl::int_<64>
>::type tag_type;
    //
    // Likewise use internal promotion, so we evaluate at a higher
    // precision internally if it's appropriate:
    //
- typedef typename tools::evaluation<result_type>::type eval_type;
+ typedef typename policy::evaluation<result_type, Policy>::type eval_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
    //
    // And get the result, negating where required:
    //
- return s * tools::checked_narrowing_cast<result_type>(
- detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), static_cast<tag_type const*>(0)), BOOST_CURRENT_FUNCTION);
+ return s * policy::checked_narrowing_cast<result_type, forwarding_policy>(
+ detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), forwarding_policy(), static_cast<tag_type const*>(0)), function);
 }
 
-template <class T>
-typename tools::promote_args<T>::type erf_inv(T z)
+template <class T, class Policy>
+typename tools::promote_args<T>::type erf_inv(T z, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
    //
    // Begin by testing for domain errors, and other special cases:
    //
+ static const char* function = "boost::math::erf_inv<%1%>(%1%, %1%)";
    if((z < -1) || (z > 1))
- tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "Argument outside range [-1, 1] in inverse erf function (got p=%1%).", z);
+ policy::raise_domain_error<result_type>(function, "Argument outside range [-1, 1] in inverse erf function (got p=%1%).", z, pol);
    if(z == 1)
- return tools::overflow_error<result_type>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<result_type>(function, 0, pol);
    if(z == -1)
- return -tools::overflow_error<result_type>(BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<result_type>(function, 0, pol);
    if(z == 0)
       return 0;
    //
@@ -409,23 +417,45 @@
    // A bit of meta-programming to figure out which implementation
    // to use, based on the number of bits in the mantissa of T:
    //
- typedef typename mpl::if_c<
- std::numeric_limits<result_type>::is_specialized
- &&
- (std::numeric_limits<result_type>::digits <= 64),
- mpl::int_<64>,
- mpl::int_<0>
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::or_<mpl::less_equal<precision_type, mpl::int_<0> >, mpl::greater<precision_type, mpl::int_<64> > >,
+ mpl::int_<0>,
+ mpl::int_<64>
>::type tag_type;
    //
    // Likewise use internal promotion, so we evaluate at a higher
    // precision internally if it's appropriate:
    //
- typedef typename tools::evaluation<result_type>::type eval_type;
+ typedef typename policy::evaluation<result_type, Policy>::type eval_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+ //
+ // Likewise use internal promotion, so we evaluate at a higher
+ // precision internally if it's appropriate:
+ //
+ typedef typename policy::evaluation<result_type, Policy>::type eval_type;
    //
    // And get the result, negating where required:
    //
- return s * tools::checked_narrowing_cast<result_type>(
- detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), static_cast<tag_type const*>(0)), BOOST_CURRENT_FUNCTION);
+ return s * policy::checked_narrowing_cast<result_type, forwarding_policy>(
+ detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), forwarding_policy(), static_cast<tag_type const*>(0)), function);
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type erfc_inv(T z)
+{
+ return erfc_inv(z, policy::policy<>());
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type erf_inv(T z)
+{
+ return erf_inv(z, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -18,21 +18,21 @@
 
 namespace boost{ namespace math{ namespace detail{
 
-template <class T>
+template <class T, class Policy>
 struct gamma_inva_t
 {
    gamma_inva_t(T z_, T p_, bool invert_) : z(z_), p(p_), invert(invert_) {}
    T operator()(T a)
    {
- return invert ? p - boost::math::gamma_q(a, z) : boost::math::gamma_p(a, z) - p;
+ return invert ? p - boost::math::gamma_q(a, z, Policy()) : boost::math::gamma_p(a, z, Policy()) - p;
    }
 private:
    T z, p;
    bool invert;
 };
 
-template <class T>
-T inverse_poisson_cornish_fisher(T lambda, T p, T q)
+template <class T, class Policy>
+T inverse_poisson_cornish_fisher(T lambda, T p, T q, const Policy& pol)
 {
    using namespace std;
    // mean:
@@ -44,7 +44,7 @@
    // kurtosis:
    // T k = 1/lambda;
    // Get the inverse of a std normal distribution:
- T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p) * constants::root_two<T>();
+ T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>();
    // Set the sign:
    if(p < 0.5)
       x = -x;
@@ -62,8 +62,8 @@
    return w > tools::min_value<T>() ? w : tools::min_value<T>();
 }
 
-template <class T>
-T gamma_inva_imp(const T& z, const T& p, const T& q)
+template <class T, class Policy>
+T gamma_inva_imp(const T& z, const T& p, const T& q, const Policy& pol)
 {
    using namespace std; // for ADL of std lib math functions
    //
@@ -81,11 +81,11 @@
    // Function object, this is the functor whose root
    // we have to solve:
    //
- gamma_inva_t<T> f(z, (p < q) ? p : q, (p < q) ? false : true);
+ gamma_inva_t<T, Policy> f(z, (p < q) ? p : q, (p < q) ? false : true);
    //
    // Tolerance: full precision.
    //
- tools::eps_tolerance<T> tol(tools::digits<T>());
+ tools::eps_tolerance<T> tol(policy::digits<T, Policy>());
    //
    // Now figure out a starting guess for what a may be,
    // we'll start out with a value that'll put p or q
@@ -105,7 +105,7 @@
       // when z is very small. Also set our step-factor according
       // to how accurate we think the result is likely to be:
       //
- guess = 1 + inverse_poisson_cornish_fisher(z, q, p);
+ guess = 1 + inverse_poisson_cornish_fisher(z, q, p, pol);
       if(z > 5)
       {
          if(z > 1000)
@@ -138,24 +138,36 @@
    // Poisson distribution as our derivative, but that's
    // even worse performance-wise than the generic method :-(
    //
- std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, false, tol, max_iter);
+ std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, false, tol, max_iter, pol);
    if(max_iter >= 200)
- tools::logic_error<T>(BOOST_CURRENT_FUNCTION, "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first);
+ policy::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;
 }
 
 } // namespace detail
 
+template <class T, class Policy>
+inline T gamma_p_inva(T x, T p, const Policy& pol)
+{
+ return detail::gamma_inva_imp(x, p, 1 - p, pol);
+}
+
+template <class T, class Policy>
+inline T gamma_q_inva(T x, T q, const Policy& pol)
+{
+ return detail::gamma_inva_imp(x, 1 - q, q, pol);
+}
+
 template <class T>
 inline T gamma_p_inva(T x, T p)
 {
- return detail::gamma_inva_imp(x, p, 1 - p);
+ return detail::gamma_inva_imp(x, p, 1 - p, policy::policy<>());
 }
 
 template <class T>
 inline T gamma_q_inva(T x, T q)
 {
- return detail::gamma_inva_imp(x, 1 - q, q);
+ return detail::gamma_inva_imp(x, 1 - q, q, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -18,23 +18,23 @@
 
 namespace boost{ namespace math{ namespace detail{
 
-template <class T>
+template <class T, class Policy>
 struct beta_inv_ab_t
 {
    beta_inv_ab_t(T b_, T z_, T p_, bool invert_, bool swap_ab_) : b(b_), z(z_), p(p_), invert(invert_), swap_ab(swap_ab_) {}
    T operator()(T a)
    {
       return invert ?
- p - boost::math::ibetac(swap_ab ? b : a, swap_ab ? a : b, z)
- : boost::math::ibeta(swap_ab ? b : a, swap_ab ? a : b, z) - p;
+ p - boost::math::ibetac(swap_ab ? b : a, swap_ab ? a : b, z, Policy())
+ : boost::math::ibeta(swap_ab ? b : a, swap_ab ? a : b, z, Policy()) - p;
    }
 private:
    T b, z, p;
    bool invert, swap_ab;
 };
 
-template <class T>
-T inverse_negative_binomial_cornish_fisher(T n, T sf, T sfc, T p, T q)
+template <class T, class Policy>
+T inverse_negative_binomial_cornish_fisher(T n, T sf, T sfc, T p, T q, const Policy& pol)
 {
    using namespace std;
    // mean:
@@ -47,7 +47,7 @@
    // kurtosis:
    T k = (6 - sf * (5+sfc)) / (n * (sfc));
    // Get the inverse of a std normal distribution:
- T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p) * constants::root_two<T>();
+ T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>();
    // Set the sign:
    if(p < 0.5)
       x = -x;
@@ -66,8 +66,8 @@
    return w;
 }
 
-template <class T>
-T ibeta_inv_ab_imp(const T& b, const T& z, const T& p, const T& q, bool swap_ab)
+template <class T, class Policy>
+T ibeta_inv_ab_imp(const T& b, const T& z, const T& p, const T& q, bool swap_ab, const Policy& pol)
 {
    using namespace std; // for ADL of std lib math functions
    //
@@ -86,11 +86,11 @@
    // Function object, this is the functor whose root
    // we have to solve:
    //
- beta_inv_ab_t<T> f(b, z, (p < q) ? p : q, (p < q) ? false : true, swap_ab);
+ beta_inv_ab_t<T, Policy> f(b, z, (p < q) ? p : q, (p < q) ? false : true, swap_ab);
    //
    // Tolerance: full precision.
    //
- tools::eps_tolerance<T> tol(tools::digits<T>());
+ tools::eps_tolerance<T> tol(policy::digits<T, Policy>());
    //
    // Now figure out a starting guess for what a may be,
    // we'll start out with a value that'll put p or q
@@ -124,7 +124,7 @@
       }
    }
    if(n * n * n * u * sf > 0.005)
- guess = 1 + inverse_negative_binomial_cornish_fisher(n, sf, sfc, u, v);
+ guess = 1 + inverse_negative_binomial_cornish_fisher(n, sf, sfc, u, v, pol);
 
    if(guess < 10)
    {
@@ -147,36 +147,60 @@
    // Max iterations permitted:
    //
    boost::uintmax_t max_iter = 200;
- std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, swap_ab ? true : false, tol, max_iter);
+ std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, swap_ab ? true : false, tol, max_iter, pol);
    if(max_iter >= 200)
- tools::logic_error<T>(BOOST_CURRENT_FUNCTION, "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first);
+ policy::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;
 }
 
 } // namespace detail
 
+template <class T, class Policy>
+inline T ibeta_inva(T b, T x, T p, const Policy& pol)
+{
+ return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, false, pol);
+}
+
+template <class T, class Policy>
+inline T ibetac_inva(T b, T x, T q, const Policy& pol)
+{
+ return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, false, pol);
+}
+
+template <class T, class Policy>
+inline T ibeta_invb(T b, T x, T p, const Policy& pol)
+{
+ return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, true, pol);
+}
+
+template <class T, class Policy>
+inline T ibetac_invb(T b, T x, T q, const Policy& pol)
+{
+ return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, true, pol);
+}
+
 template <class T>
 inline T ibeta_inva(T b, T x, T p)
 {
- return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, false);
+ return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, false, policy::policy<>());
 }
 
 template <class T>
 inline T ibetac_inva(T b, T x, T q)
 {
- return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, false);
+ return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, false, policy::policy<>());
 }
 
 template <class T>
 inline T ibeta_invb(T b, T x, T p)
 {
- return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, true);
+ return detail::ibeta_inv_ab_imp(b, x, p, 1 - p, true, policy::policy<>());
 }
 
 template <class T>
 inline T ibetac_invb(T b, T x, T q)
 {
- return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, true);
+ return detail::ibeta_inv_ab_imp(b, x, 1 - q, q, true, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inverse.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inverse.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/ibeta_inverse.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -52,8 +52,8 @@
 // Journal of Computation and Applied Mathematics 41 (1992) 145-157.
 // Section 2.
 //
-template <class T>
-T temme_method_1_ibeta_inverse(T a, T b, T z)
+template <class T, class Policy>
+T temme_method_1_ibeta_inverse(T a, T b, T z, const Policy& pol)
 {
    using namespace std; // ADL of std names
 
@@ -62,7 +62,7 @@
    // get the first approximation for eta from the inverse
    // error function (Eq: 2.9 and 2.10).
    //
- T eta0 = boost::math::erfc_inv(2 * z);
+ T eta0 = boost::math::erfc_inv(2 * z, pol);
    eta0 /= -sqrt(a / 2);
 
    T terms[4] = { eta0 };
@@ -130,8 +130,8 @@
 // Journal of Computation and Applied Mathematics 41 (1992) 145-157.
 // Section 3.
 //
-template <class T>
-T temme_method_2_ibeta_inverse(T /*a*/, T /*b*/, T z, T r, T theta)
+template <class T, class Policy>
+T temme_method_2_ibeta_inverse(T /*a*/, T /*b*/, T z, T r, T theta, const Policy& pol)
 {
    using namespace std; // ADL of std names
 
@@ -139,7 +139,7 @@
    // Get first estimate for eta, see Eq 3.9 and 3.10,
    // but note there is a typo in Eq 3.10:
    //
- T eta0 = boost::math::erfc_inv(2 * z);
+ T eta0 = boost::math::erfc_inv(2 * z, pol);
    eta0 /= -sqrt(r / 2);
 
    T s = sin(theta);
@@ -296,7 +296,7 @@
    // And iterate:
    //
    x = tools::newton_raphson_iterate(
- temme_root_finder<T>(-lu, alpha), x, lower, upper, tools::digits<T>() / 2);
+ temme_root_finder<T>(-lu, alpha), x, lower, upper, policy::digits<T, Policy>() / 2);
 
    return x;
 }
@@ -307,8 +307,8 @@
 // Journal of Computation and Applied Mathematics 41 (1992) 145-157.
 // Section 4.
 //
-template <class T>
-T temme_method_3_ibeta_inverse(T a, T b, T p, T q)
+template <class T, class Policy>
+T temme_method_3_ibeta_inverse(T a, T b, T p, T q, const Policy& pol)
 {
    using namespace std; // ADL of std names
 
@@ -318,9 +318,9 @@
    //
    T eta0;
    if(p < q)
- eta0 = boost::math::gamma_q_inv(b, p);
+ eta0 = boost::math::gamma_q_inv(b, p, pol);
    else
- eta0 = boost::math::gamma_p_inv(b, q);
+ eta0 = boost::math::gamma_p_inv(b, q, pol);
    eta0 /= a;
    //
    // Define the variables and powers we'll need later on:
@@ -399,14 +399,14 @@
    T upper = eta < mu ? 1 : cross;
    T x = (lower + upper) / 2;
    x = tools::newton_raphson_iterate(
- temme_root_finder<T>(u, mu), x, lower, upper, tools::digits<T>() / 2);
+ temme_root_finder<T>(u, mu), x, lower, upper, policy::digits<T, Policy>() / 2);
 #ifdef BOOST_INSTRUMENT
    std::cout << "Estimating x with Temme method 3: " << x << std::endl;
 #endif
    return x;
 }
 
-template <class T, class L>
+template <class T, class Policy>
 struct ibeta_roots
 {
    ibeta_roots(T _a, T _b, T t, bool inv = false)
@@ -420,7 +420,7 @@
       
       T f1;
       T y = 1 - x;
- T f = ibeta_imp(a, b, x, L(), invert, true, &f1) - target;
+ T f = ibeta_imp(a, b, x, Policy(), invert, true, &f1) - target;
       if(invert)
          f1 = -f1;
       if(y == 0)
@@ -445,8 +445,8 @@
    bool invert;
 };
 
-template <class T, class L>
-T ibeta_inv_imp(T a, T b, T p, T q, const L& l, T* py)
+template <class T, class Policy>
+T ibeta_inv_imp(T a, T b, T p, T q, const Policy& pol, T* py)
 {
    using namespace std; // For ADL of math functions.
 
@@ -501,7 +501,7 @@
    {
       //
       // We have a Student's T distribution:
- x = estimate_ibeta_inv_from_t_dist(a, p, q, &y, l);
+ x = estimate_ibeta_inv_from_t_dist(a, p, q, &y, pol);
    }
    else if(a + b > 5)
    {
@@ -529,7 +529,7 @@
          // for x will never be much larger than p, so we don't have
          // to worry about cancellation as long as p is small.
          //
- x = temme_method_1_ibeta_inverse(a, b, p);
+ x = temme_method_1_ibeta_inverse(a, b, p, pol);
          y = 1 - x;
       }
       else
@@ -550,10 +550,10 @@
             T ppa = pow(p, 1/a);
             if((ppa < 0.0025) && (a + b < 200))
             {
- x = ppa * pow(a * boost::math::beta(a, b), 1/a);
+ x = ppa * pow(a * boost::math::beta(a, b, pol), 1/a);
             }
             else
- x = temme_method_2_ibeta_inverse(a, b, p, r, theta);
+ x = temme_method_2_ibeta_inverse(a, b, p, r, theta, pol);
             y = 1 - x;
          }
          else
@@ -578,7 +578,7 @@
             //
             T bet = 0;
             if(b < 2)
- bet = boost::math::beta(a, b);
+ bet = boost::math::beta(a, b, pol);
             if(bet != 0)
             {
                y = pow(b * q * bet, 1/b);
@@ -588,7 +588,7 @@
                y = 1;
             if(y > 1e-5)
             {
- x = temme_method_3_ibeta_inverse(a, b, p, q);
+ x = temme_method_3_ibeta_inverse(a, b, p, q, pol);
                y = 1 - x;
             }
          }
@@ -605,7 +605,7 @@
       // Now we need to ensure that we start our iteration from the
       // right side of the inflection point:
       //
- T fs = boost::math::ibeta(a, b, xs) - p;
+ T fs = boost::math::ibeta(a, b, xs, pol) - p;
       if(fabs(fs) / p < tools::epsilon<T>() * 3)
       {
          // The result is at the point of inflection, best just return it:
@@ -619,7 +619,7 @@
          invert = true;
          xs = 1 - xs;
       }
- T xg = pow(a * p * boost::math::beta(a, b), 1/a);
+ T xg = pow(a * p * boost::math::beta(a, b, pol), 1/a);
       x = xg / (1 + xg);
       y = 1 / (1 + xg);
       //
@@ -641,7 +641,7 @@
       //
       T xs = (a - 1) / (a + b - 2);
       T xs2 = (b - 1) / (a + b - 2);
- T ps = boost::math::ibeta(a, b, xs) - p;
+ T ps = boost::math::ibeta(a, b, xs, pol) - p;
 
       if(ps < 0)
       {
@@ -654,9 +654,9 @@
       // Estimate x and y, using expm1 to get a good estimate
       // for y when it's very small:
       //
- T lx = log(p * a * boost::math::beta(a, b)) / a;
+ T lx = log(p * a * boost::math::beta(a, b, pol)) / a;
       x = exp(lx);
- y = x < 0.9 ? 1 - x : -boost::math::expm1(lx);
+ y = x < 0.9 ? 1 - x : -boost::math::expm1(lx, pol);
 
       if((b < a) && (x < 0.2))
       {
@@ -716,7 +716,7 @@
       }
       if(pow(p, 1/a) < 0.5)
       {
- x = pow(p * a * boost::math::beta(a, b), 1 / a);
+ x = pow(p * a * boost::math::beta(a, b, pol), 1 / a);
          if(x == 0)
             x = boost::math::tools::min_value<T>();
          y = 1 - x;
@@ -724,7 +724,7 @@
       else /*if(pow(q, 1/b) < 0.1)*/
       {
          // model a distorted quarter circle:
- y = pow(1 - pow(p, b*beta(a, b)), 1/b);
+ y = pow(1 - pow(p, b * boost::math::beta(a, b, pol)), 1/b);
          if(y == 0)
             y = boost::math::tools::min_value<T>();
          x = 1 - y;
@@ -772,7 +772,7 @@
    //
    // Figure out how many digits to iterate towards:
    //
- int digits = boost::math::tools::digits<T>() / 2;
+ int digits = boost::math::policy::digits<T, Policy>() / 2;
    if((x < 1e-50) && ((a < 1) || (b < 1)))
    {
       //
@@ -792,7 +792,7 @@
    // depending on which is smaller:
    //
    x = boost::math::tools::halley_iterate(
- boost::math::detail::ibeta_roots<T, L>(a, b, (p < q ? p : q), (p < q ? false : true)), x, lower, upper, digits);
+ boost::math::detail::ibeta_roots<T, Policy>(a, b, (p < q ? p : q), (p < q ? false : true)), x, lower, upper, digits);
    //
    // We don't really want these asserts here, but they are useful for sanity
    // checking that we have the limits right, uncomment if you suspect bugs *only*.
@@ -811,21 +811,27 @@
 
 } // namespace detail
 
-template <class T1, class T2, class T3, class T4>
+template <class T1, class T2, class T3, class T4, class Policy>
 inline typename tools::promote_args<T1, T2, T3, T4>::type
- ibeta_inv(T1 a, T2 b, T3 p, T4* py)
+ ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy& pol)
 {
+ static const char* function = "boost::math::ibeta_inv<%1%>(%1%,%1%,%1%)";
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
    if(a <= 0)
- return tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a);
+ return policy::raise_domain_error<result_type>(function, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- return tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b);
+ return policy::raise_domain_error<result_type>(function, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b, pol);
    if((p < 0) || (p > 1))
- return tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "Argument p outside the range [0,1] in the incomplete beta function inverse (got p=%1%).", p);
+ return policy::raise_domain_error<result_type>(function, "Argument p outside the range [0,1] in the incomplete beta function inverse (got p=%1%).", p, pol);
 
    value_type rx, ry;
 
@@ -834,35 +840,54 @@
          static_cast<value_type>(b),
          static_cast<value_type>(p),
          static_cast<value_type>(1 - p),
- evaluation_type(), &ry);
+ forwarding_policy(), &ry);
 
- if(py) *py = tools::checked_narrowing_cast<T4>(ry, BOOST_CURRENT_FUNCTION);
- return tools::checked_narrowing_cast<result_type>(rx, BOOST_CURRENT_FUNCTION);
+ if(py) *py = policy::checked_narrowing_cast<T4, forwarding_policy>(ry, function);
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(rx, function);
+}
+
+template <class T1, class T2, class T3, class T4>
+inline typename tools::promote_args<T1, T2, T3, T4>::type
+ ibeta_inv(T1 a, T2 b, T3 p, T4* py)
+{
+ return ibeta_inv(a, b, p, py, policy::policy<>());
 }
 
 template <class T1, class T2, class T3>
 inline typename tools::promote_args<T1, T2, T3>::type
    ibeta_inv(T1 a, T2 b, T3 p)
 {
- BOOST_FPU_EXCEPTION_GUARD
- return ibeta_inv(a, b, p, static_cast<T1*>(0));
+ return ibeta_inv(a, b, p, static_cast<T1*>(0), policy::policy<>());
 }
 
-template <class T1, class T2, class T3, class T4>
+template <class T1, class T2, class T3, class Policy>
+inline typename tools::promote_args<T1, T2, T3>::type
+ ibeta_inv(T1 a, T2 b, T3 p, const Policy& pol)
+{
+ return ibeta_inv(a, b, p, static_cast<T1*>(0), pol);
+}
+
+template <class T1, class T2, class T3, class T4, class Policy>
 inline typename tools::promote_args<T1, T2, T3, T4>::type
- ibetac_inv(T1 a, T2 b, T3 q, T4* py)
+ ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy& pol)
 {
+ static const char* function = "boost::math::ibetac_inv<%1%>(%1%,%1%,%1%)";
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
    if(a <= 0)
- tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<result_type>(function, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a, pol);
    if(b <= 0)
- tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b);
+ policy::raise_domain_error<result_type>(function, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b, pol);
    if((q < 0) || (q > 1))
- tools::domain_error<result_type>(BOOST_CURRENT_FUNCTION, "Argument q outside the range [0,1] in the incomplete beta function inverse (got q=%1%).", q);
+ policy::raise_domain_error<result_type>(function, "Argument q outside the range [0,1] in the incomplete beta function inverse (got q=%1%).", q, pol);
 
    value_type rx, ry;
 
@@ -871,18 +896,31 @@
          static_cast<value_type>(b),
          static_cast<value_type>(1 - q),
          static_cast<value_type>(q),
- evaluation_type(), &ry);
+ forwarding_policy(), &ry);
 
- if(py) *py = tools::checked_narrowing_cast<T4>(ry, BOOST_CURRENT_FUNCTION);
- return tools::checked_narrowing_cast<result_type>(rx, BOOST_CURRENT_FUNCTION);
+ if(py) *py = policy::checked_narrowing_cast<T4, forwarding_policy>(ry, function);
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(rx, function);
+}
+
+template <class T1, class T2, class T3, class T4>
+inline typename tools::promote_args<T1, T2, T3, T4>::type
+ ibetac_inv(T1 a, T2 b, T3 q, T4* py)
+{
+ return ibetac_inv(a, b, q, py, policy::policy<>());
 }
 
 template <class RT1, class RT2, class RT3>
 inline typename tools::promote_args<RT1, RT2, RT3>::type
    ibetac_inv(RT1 a, RT2 b, RT3 q)
 {
- BOOST_FPU_EXCEPTION_GUARD
- return ibetac_inv(a, b, q, static_cast<RT1*>(0));
+ return ibetac_inv(a, b, q, static_cast<RT1*>(0), policy::policy<>());
+}
+
+template <class RT1, class RT2, class RT3, class Policy>
+inline typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_inv(RT1 a, RT2 b, RT3 q, const Policy& pol)
+{
+ return ibetac_inv(a, b, q, static_cast<RT1*>(0), pol);
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/igamma_inverse.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/igamma_inverse.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/igamma_inverse.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/math/special_functions/sign.hpp>
 #include <boost/math/tools/roots.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 namespace boost{ namespace math{
 
@@ -71,8 +71,8 @@
    return sum;
 }
 
-template <class T>
-inline T didonato_FN(T p, T a, T x, unsigned N, T tolerance)
+template <class T, class Policy>
+inline T didonato_FN(T p, T a, T x, unsigned N, T tolerance, const Policy& pol)
 {
    //
    // Computation of the Incomplete Gamma Function Ratios and their Inverse
@@ -83,12 +83,12 @@
    // See equation 34.
    //
    using namespace std;
- T u = log(p) + boost::math::lgamma(a + 1);
+ T u = log(p) + boost::math::lgamma(a + 1, pol);
    return exp((u + x - log(didonato_SN(a, x, N, tolerance))) / a);
 }
 
-template <class T>
-T estimate_inverse_gamma(T a, T p, T q)
+template <class T, class Policy>
+T estimate_inverse_gamma(T a, T p, T q, const Policy& pol)
 {
    //
    // In order to understand what's going on here, you will
@@ -107,7 +107,7 @@
       result = -log(q);
    else if(a < 1)
    {
- T g = boost::math::tgamma(a);
+ T g = boost::math::tgamma(a, pol);
       T b = q * g;
       if((b > 0.6) || ((b >= 0.45) && (a >= 0.3)))
       {
@@ -205,7 +205,7 @@
          else
          {
             T D = (std::max)(T(2), a * (a - 1));
- T lg = boost::math::lgamma(a);
+ T lg = boost::math::lgamma(a, pol);
             T lb = log(q) + lg;
             if(lb < -D * 2.3)
             {
@@ -243,10 +243,10 @@
       else
       {
          // DiDonato and Morris Eq 35:
- T z = didonato_FN(p, a, w, 0, T(0));
- z = didonato_FN(p, a, z, 2, T(0));
- z = didonato_FN(p, a, z, 2, T(0));
- z = didonato_FN(p, a, z, 3, T(0));
+ T z = didonato_FN(p, a, w, 0, T(0), pol);
+ z = didonato_FN(p, a, z, 2, T(0), pol);
+ z = didonato_FN(p, a, z, 2, T(0), pol);
+ z = didonato_FN(p, a, z, 3, T(0), pol);
 
          if((z <= 0.01 * (a + 1)) || (z > 0.7 * (a + 1)))
          {
@@ -255,8 +255,8 @@
          else
          {
             // DiDonato and Morris Eq 36:
- T zb = didonato_FN(p, a, z, 100, T(1e-4));
- T u = log(p) + boost::math::lgamma(a + 1);
+ T zb = didonato_FN(p, a, z, 100, T(1e-4), pol);
+ T u = log(p) + boost::math::lgamma(a + 1, pol);
             result = zb * (1 - (a * log(zb) - zb - u + log(didonato_SN(a, z, 100, T(1e-4)))) / (a - zb));
          }
       }
@@ -264,7 +264,7 @@
    return result;
 }
 
-template <class T>
+template <class T, class Policy>
 struct gamma_p_inverse_func
 {
    gamma_p_inverse_func(T a_, T p_, bool inv) : a(a_), p(p_), invert(inv)
@@ -292,8 +292,14 @@
       // Calculate P(x) - p and the first two derivates, or if the invert
       // flag is set, then Q(x) - q and it's derivatives.
       //
- typedef typename lanczos::lanczos_traits<T>::value_type value_type;
- typedef typename lanczos::lanczos_traits<T>::evaluation_type evaluation_type;
+ typedef typename policy::evaluation<T, Policy>::type value_type;
+ typedef typename lanczos::lanczos<T, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
       using namespace std; // For ADL of std functions.
 
@@ -302,8 +308,8 @@
       f = static_cast<T>(boost::math::detail::gamma_incomplete_imp(
                static_cast<value_type>(a),
                static_cast<value_type>(x),
- true, invert, evaluation_type(),
- &ft));
+ true, invert,
+ forwarding_policy(), &ft));
       f1 = static_cast<T>(ft);
       T f2;
       T div = (a - x - 1) / x;
@@ -331,20 +337,22 @@
    bool invert;
 };
 
-template <class T>
-T gamma_p_inv_imp(T a, T p)
+template <class T, class Policy>
+T gamma_p_inv_imp(T a, T p, const Policy& pol)
 {
    using namespace std; // ADL of std functions.
 
+ static const char* function = "boost::math::gamma_p_inv<%1%>(%1%, %1%)";
+
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a);
+ policy::raise_domain_error<T>(function, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a, pol);
    if((p < 0) || (p > 1))
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got p=%1%).", p);
+ policy::raise_domain_error<T>(function, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got p=%1%).", p, pol);
    if(p == 1)
       return tools::max_value<T>();
    if(p == 0)
       return 0;
- T guess = detail::estimate_inverse_gamma(a, p, 1 - p);
+ T guess = detail::estimate_inverse_gamma(a, p, 1 - p, pol);
    T lower = tools::min_value<T>();
    if(guess <= lower)
       guess = tools::min_value<T>();
@@ -354,37 +362,39 @@
    // large convergence is slow, so we'll bump it up to full
    // precision to prevent premature termination of the root-finding routine.
    //
- unsigned digits = (tools::digits<T>() * 2) / 3;
- if((a < 0.125) && (fabs(gamma_p_derivative(a, guess)) > 1 / sqrt(tools::epsilon<T>())))
- digits = tools::digits<T>() - 2;
+ unsigned digits = (policy::digits<T, Policy>() * 2) / 3;
+ if((a < 0.125) && (fabs(gamma_p_derivative(a, guess, pol)) > 1 / sqrt(tools::epsilon<T>())))
+ digits = policy::digits<T, Policy>() - 2;
    //
    // Go ahead and iterate:
    //
    guess = tools::halley_iterate(
- detail::gamma_p_inverse_func<T>(a, p, false),
+ detail::gamma_p_inverse_func<T, Policy>(a, p, false),
       guess,
       lower,
       tools::max_value<T>(),
       digits);
    if(guess == lower)
- guess = tools::underflow_error<T>(BOOST_CURRENT_FUNCTION, "Expected result known to be non-zero, but is smaller than the smallest available number.");
+ guess = policy::raise_underflow_error<T>(function, "Expected result known to be non-zero, but is smaller than the smallest available number.", pol);
    return guess;
 }
 
-template <class T>
-T gamma_q_inv_imp(T a, T q)
+template <class T, class Policy>
+T gamma_q_inv_imp(T a, T q, const Policy& pol)
 {
    using namespace std; // ADL of std functions.
 
+ static const char* function = "boost::math::gamma_q_inv<%1%>(%1%, %1%)";
+
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a);
+ policy::raise_domain_error<T>(function, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a, pol);
    if((q < 0) || (q > 1))
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got q=%1%).", q);
+ policy::raise_domain_error<T>(function, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got q=%1%).", q, pol);
    if(q == 0)
       return tools::max_value<T>();
    if(q == 1)
       return 0;
- T guess = detail::estimate_inverse_gamma(a, 1 - q, q);
+ T guess = detail::estimate_inverse_gamma(a, 1 - q, q, pol);
    T lower = tools::min_value<T>();
    if(guess <= lower)
       guess = tools::min_value<T>();
@@ -394,43 +404,57 @@
    // large convergence is slow, so we'll bump it up to full
    // precision to prevent premature termination of the root-finding routine.
    //
- unsigned digits = (tools::digits<T>() * 2) / 3;
- if((a < 0.125) && (fabs(gamma_p_derivative(a, guess)) > 1 / sqrt(tools::epsilon<T>())))
- digits = tools::digits<T>();
+ unsigned digits = (policy::digits<T, Policy>() * 2) / 3;
+ if((a < 0.125) && (fabs(gamma_p_derivative(a, guess, pol)) > 1 / sqrt(tools::epsilon<T>())))
+ digits = policy::digits<T, Policy>();
    //
    // Go ahead and iterate:
    //
    guess = tools::halley_iterate(
- detail::gamma_p_inverse_func<T>(a, q, true),
+ detail::gamma_p_inverse_func<T, Policy>(a, q, true),
       guess,
       lower,
       tools::max_value<T>(),
       digits);
    if(guess == lower)
- guess = tools::underflow_error<T>(BOOST_CURRENT_FUNCTION, "Expected result known to be non-zero, but is smaller than the smallest available number.");
+ guess = policy::raise_underflow_error<T>(function, "Expected result known to be non-zero, but is smaller than the smallest available number.", pol);
    return guess;
 }
 
 } // namespace detail
 
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- gamma_p_inv(T1 a, T2 p)
+ gamma_p_inv(T1 a, T2 p, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2>::type result_type;
    return detail::gamma_p_inv_imp(
       static_cast<result_type>(a),
- static_cast<result_type>(p));
+ static_cast<result_type>(p), pol);
 }
 
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- gamma_q_inv(T1 a, T2 p)
+ gamma_q_inv(T1 a, T2 p, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2>::type result_type;
    return detail::gamma_q_inv_imp(
       static_cast<result_type>(a),
- static_cast<result_type>(p));
+ static_cast<result_type>(p), pol);
+}
+
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ gamma_p_inv(T1 a, T2 p)
+{
+ return gamma_p_inv(a, p, policy::policy<>());
+}
+
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ gamma_q_inv(T1 a, T2 p)
+{
+ return gamma_q_inv(a, p, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/igamma_large.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/igamma_large.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/igamma_large.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -48,16 +48,11 @@
 namespace boost{ namespace math{ namespace detail{
 
 //
-// Forward declaration, computes log(1+x) - x:
-//
-template <class T>
-T log1pmx(T x);
-//
 // This version will never be called (at runtime), it's a stub used
 // when T is unsuitable to be passed to these routines:
 //
-template <class T>
-inline T igamma_temme_large(T, T, mpl::int_<0> const *)
+template <class T, class Policy>
+inline T igamma_temme_large(T, T, const Policy& pol, mpl::int_<0> const *)
 {
    // stub function, should never actually be called
    BOOST_ASSERT(0);
@@ -67,12 +62,12 @@
 // This version is accurate for up to 64-bit mantissa's,
 // (80-bit long double, or 10^-20).
 //
-template <class T>
-T igamma_temme_large(T a, T x, mpl::int_<64> const *)
+template <class T, class Policy>
+T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<64> const *)
 {
    using namespace std; // ADL of std functions
    T sigma = (x - a) / a;
- T phi = -log1pmx(sigma);
+ T phi = -log1pmx(sigma, pol);
    T y = a * phi;
    T z = sqrt(2 * phi);
    if(x < a)
@@ -264,7 +259,7 @@
    if(x < a)
       result = -result;
 
- result += boost::math::erfc(sqrt(y)) / 2;
+ result += boost::math::erfc(sqrt(y), pol) / 2;
 
    return result;
 }
@@ -272,12 +267,12 @@
 // This one is accurate for 53-bit mantissa's
 // (IEEE double precision or 10^-17).
 //
-template <class T>
-T igamma_temme_large(T a, T x, mpl::int_<53> const *)
+template <class T, class Policy>
+T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<53> const *)
 {
    using namespace std; // ADL of std functions
    T sigma = (x - a) / a;
- T phi = -log1pmx(sigma);
+ T phi = -log1pmx(sigma, pol);
    T y = a * phi;
    T z = sqrt(2 * phi);
    if(x < a)
@@ -406,7 +401,7 @@
    if(x < a)
       result = -result;
 
- result += boost::math::erfc(sqrt(y)) / 2;
+ result += boost::math::erfc(sqrt(y), pol) / 2;
 
    return result;
 }
@@ -414,12 +409,12 @@
 // This one is accurate for 24-bit mantissa's
 // (IEEE float precision, or 10^-8)
 //
-template <class T>
-T igamma_temme_large(T a, T x, mpl::int_<24> const *)
+template <class T, class Policy>
+T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<24> const *)
 {
    using namespace std; // ADL of std functions
    T sigma = (x - a) / a;
- T phi = -log1pmx(sigma);
+ T phi = -log1pmx(sigma, pol);
    T y = a * phi;
    T z = sqrt(2 * phi);
    if(x < a)
@@ -459,7 +454,7 @@
    if(x < a)
       result = -result;
 
- result += boost::math::erfc(sqrt(y)) / 2;
+ result += boost::math::erfc(sqrt(y), pol) / 2;
 
    return result;
 }
@@ -470,12 +465,12 @@
 // It's use for a < 200 is not recomended, that would
 // require many more terms in the polynomials.
 //
-template <class T>
-T igamma_temme_large(T a, T x, mpl::int_<113> const *)
+template <class T, class Policy>
+T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<113> const *)
 {
    using namespace std; // ADL of std functions
    T sigma = (x - a) / a;
- T phi = -log1pmx(sigma);
+ T phi = -log1pmx(sigma, pol);
    T y = a * phi;
    T z = sqrt(2 * phi);
    if(x < a)
@@ -756,7 +751,7 @@
    if(x < a)
       result = -result;
 
- result += boost::math::erfc(sqrt(y)) / 2;
+ result += boost::math::erfc(sqrt(y), pol) / 2;
 
    return result;
 }

Modified: sandbox/math_toolkit/boost/math/special_functions/detail/t_distribution_inv.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/detail/t_distribution_inv.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/detail/t_distribution_inv.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -17,8 +17,8 @@
 // G. W. Hill, Algorithm 396, Student’s t-Quantiles,
 // Communications of the ACM, 13(10): 619-620, Oct., 1970.
 //
-template <class T>
-T inverse_students_t_hill(T ndf, T u)
+template <class T, class Policy>
+T inverse_students_t_hill(T ndf, T u, const Policy& pol)
 {
    using namespace std;
    BOOST_ASSERT(u <= 0.5);
@@ -26,7 +26,7 @@
    T a, b, c, d, q, x, y;
 
    if (ndf > 1e20f)
- return -boost::math::erfc_inv(2 * u) * constants::root_two<T>();
+ return -boost::math::erfc_inv(2 * u, pol) * constants::root_two<T>();
 
    a = 1 / (ndf - 0.5f);
    b = 48 / (a * a);
@@ -39,14 +39,14 @@
       //
       // Asymptotic inverse expansion about normal:
       //
- x = -boost::math::erfc_inv(2 * u) * constants::root_two<T>();
+ x = -boost::math::erfc_inv(2 * u, pol) * constants::root_two<T>();
       y = x * x;
 
       if (ndf < 5)
          c += 0.3f * (ndf - 4.5f) * (x + 0.6f);
       c += (((0.05f * d * x - 5) * x - 7) * x - 2) * x + b;
       y = (((((0.4f * y + 6.3f) * y + 36) * y + 94.5f) / c - y - 3) / b + 1) * x;
- y = boost::math::expm1(a * y * y);
+ y = boost::math::expm1(a * y * y, pol);
    }
    else
    {
@@ -67,13 +67,13 @@
 // the inverse cumulative distribution function."
 // Journal of Computational Finance, Vol 9 Issue 4, pp 37-73, Summer 2006
 //
-template <class T, class L>
-T inverse_students_t_tail_series(T df, T v, T /* u */, const L& l)
+template <class T, class Policy>
+T inverse_students_t_tail_series(T df, T v, T u, const Policy& pol)
 {
    using namespace std;
    // Tail series expansion, see section 6 of Shaw's paper.
    // w is calculated using Eq 60:
- T w = detail::tgamma_delta_ratio_imp(df / 2, constants::half<T>(), l)
+ T w = boost::math::tgamma_delta_ratio(df / 2, constants::half<T>(), pol)
       * sqrt(df * constants::pi<T>()) * v;
    // define some variables:
    T np2 = df + 2;
@@ -118,8 +118,8 @@
    return -result;
 }
 
-template <class T, class L>
-T inverse_students_t_body_series(T df, T u, const L& l)
+template <class T, class Policy>
+T inverse_students_t_body_series(T df, T u, const Policy& pol)
 {
    using namespace std;
    //
@@ -127,7 +127,7 @@
    //
    // Start with Eq 56 of Shaw:
    //
- T v = detail::tgamma_delta_ratio_imp(df / 2, constants::half<T>(), l)
+ T v = boost::math::tgamma_delta_ratio(df / 2, constants::half<T>(), pol)
       * sqrt(df * constants::pi<T>()) * (u - constants::half<T>());
    //
    // Workspace for the polynomial coefficients:
@@ -172,8 +172,8 @@
    return tools::evaluate_odd_polynomial(c, v);
 }
 
-template <class T, class L>
-T inverse_students_t(T df, T u, T v, const L& l, bool* pexact = 0)
+template <class T, class Policy>
+T inverse_students_t(T df, T u, T v, const Policy& pol, bool* pexact = 0)
 {
    //
    // df = number of degrees of freedom.
@@ -198,7 +198,7 @@
       // we have integer degrees of freedom, try for the special
       // cases first:
       //
- T tolerance = ldexp(1.0f, (2 * tools::digits<T>()) / 3);
+ T tolerance = ldexp(1.0f, (2 * policy::digits<T, Policy>()) / 3);
 
       switch(boost::math::tools::real_cast<int>(df))
       {
@@ -208,8 +208,6 @@
             // df = 1 is the same as the Cauchy distribution, see
             // Shaw Eq 35:
             //
- // FIXME: fails when u is small!!!
- result = tan(constants::pi<T>() * (u - constants::half<T>()));
             if(u == 0.5)
                result = 0;
             else
@@ -248,7 +246,7 @@
             // We get numeric overflow in this area:
             //
             if(u < 1e-150)
- return (invert ? -1 : 1) * inverse_students_t_hill(df, u);
+ return (invert ? -1 : 1) * inverse_students_t_hill(df, u, pol);
             //
             // Newton-Raphson iteration of a polynomial case,
             // choice of seed value is taken from Shaw's online
@@ -352,11 +350,11 @@
          T crossover = 0.2742f - df * 0.0242143f;
          if(u > crossover)
          {
- result = boost::math::detail::inverse_students_t_body_series(df, u, l);
+ result = boost::math::detail::inverse_students_t_body_series(df, u, pol);
          }
          else
          {
- result = boost::math::detail::inverse_students_t_tail_series(df, u, v, l);
+ result = boost::math::detail::inverse_students_t_tail_series(df, u, v, pol);
          }
       }
       else
@@ -369,31 +367,31 @@
          T crossover = ldexp(1.0f, tools::real_cast<int>(df / -0.654f));
          if(u > crossover)
          {
- result = boost::math::detail::inverse_students_t_hill(df, u);
+ result = boost::math::detail::inverse_students_t_hill(df, u, pol);
          }
          else
          {
- result = boost::math::detail::inverse_students_t_tail_series(df, u, v, l);
+ result = boost::math::detail::inverse_students_t_tail_series(df, u, v, pol);
          }
       }
    }
    return invert ? -result : result;
 }
 
-template <class T, class L>
-inline T estimate_ibeta_inv_from_t_dist(T a, T p, T q, T* py, const L& l)
+template <class T, class Policy>
+inline T estimate_ibeta_inv_from_t_dist(T a, T p, T q, T* py, const Policy& pol)
 {
    T u = (p > q) ? 0.5f - q / 2 : p / 2;
    T v = 1 - u; // u < 0.5 so no cancellation error
    T df = a * 2;
- T t = boost::math::detail::inverse_students_t(df, u, v, l);
+ T t = boost::math::detail::inverse_students_t(df, u, v, pol);
    T x = df / (df + t * t);
    *py = t * t / (df + t * t);
    return x;
 }
 
-template <class T, class L>
-inline T fast_students_t_quantile_imp(T df, T p, const L& /* l */, const mpl::false_*)
+template <class T, class Policy>
+inline T fast_students_t_quantile_imp(T df, T p, const Policy& pol, const mpl::false_*)
 {
    using namespace std;
    //
@@ -402,9 +400,9 @@
    //
    T probability = (p > 0.5) ? 1 - p : p;
    T t, x, y;
- x = ibeta_inv(df / 2, T(0.5), 2 * probability, &y);
+ x = ibeta_inv(df / 2, T(0.5), 2 * probability, &y, pol);
    if(df * y > tools::max_value<T>() * x)
- t = tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ t = policy::raise_overflow_error<T>("boost::math::students_t_quantile<%1%>(%1%,%1%)", 0, pol);
    else
       t = sqrt(df * y / x);
    //
@@ -415,13 +413,13 @@
    return t;
 }
 
-template <class T, class L>
-T fast_students_t_quantile_imp(T df, T p, const L& l, const mpl::true_*)
+template <class T, class Policy>
+T fast_students_t_quantile_imp(T df, T p, const Policy& pol, const mpl::true_*)
 {
    using namespace std;
    bool invert = false;
    if((df < 2) && (floor(df) != df))
- return boost::math::detail::fast_students_t_quantile_imp(df, p, l, static_cast<mpl::false_*>(0));
+ return boost::math::detail::fast_students_t_quantile_imp(df, p, pol, static_cast<mpl::false_*>(0));
    if(p > 0.5)
    {
       p = 1 - p;
@@ -431,7 +429,7 @@
    // Get an estimate of the result:
    //
    bool exact;
- T t = inverse_students_t(df, p, 1-p, l, &exact);
+ T t = inverse_students_t(df, p, 1-p, pol, &exact);
    if((t == 0) || exact)
       return invert ? -t : t; // can't do better!
    //
@@ -451,8 +449,8 @@
    // Get incomplete beta and it's derivative:
    //
    T f1;
- T f0 = xb < y ? ibeta_imp(a, constants::half<T>(), xb, l, false, true, &f1)
- : ibeta_imp(constants::half<T>(), a, y, l, true, true, &f1);
+ T f0 = xb < y ? ibeta_imp(a, constants::half<T>(), xb, pol, false, true, &f1)
+ : ibeta_imp(constants::half<T>(), a, y, pol, true, true, &f1);
 
    // Get cdf from incomplete beta result:
    T p0 = f0 / 2 - p;
@@ -486,18 +484,25 @@
    return !invert ? -t : t;
 }
 
-template <class T>
-inline T fast_students_t_quantile(T df, T p)
+template <class T, class Policy>
+inline T fast_students_t_quantile(T df, T p, const Policy& pol)
 {
- typedef typename lanczos::lanczos_traits<T>::value_type value_type;
- typedef typename lanczos::lanczos_traits<T>::evaluation_type evaluation_type;
+ typedef typename policy::evaluation<T, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
    typedef mpl::bool_<
       (std::numeric_limits<T>::digits <= 53)
        &&
       (std::numeric_limits<T>::is_specialized)> tag_type;
- return tools::checked_narrowing_cast<T>(fast_students_t_quantile_imp(static_cast<value_type>(df), static_cast<value_type>(p), evaluation_type(), static_cast<tag_type*>(0)), BOOST_CURRENT_FUNCTION);
+ return policy::checked_narrowing_cast<T, forwarding_policy>(fast_students_t_quantile_imp(static_cast<value_type>(df), static_cast<value_type>(p), pol, static_cast<tag_type*>(0)), "boost::math::students_t_quantile<%1%>(%1%,%1%,%1%)");
 }
 
 }}} // namespaces
 
 #endif // BOOST_MATH_SF_DETAIL_INV_T_HPP
+

Modified: sandbox/math_toolkit/boost/math/special_functions/digamma.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/digamma.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/digamma.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -7,10 +7,10 @@
 #define BOOST_MATH_SF_DIGAMMA_HPP
 
 #include <boost/math/tools/rational.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
 #include <boost/math/tools/promotion.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/constants/constants.hpp>
+#include <boost/mpl/comparison.hpp>
 
 namespace boost{
 namespace math{
@@ -338,8 +338,8 @@
    return result;
 }
 
-template <class T, class Tag>
-T digamma_imp(T x, const Tag* t)
+template <class T, class Tag, class Policy>
+T digamma_imp(T x, const Tag* t, const Policy& pol)
 {
    //
    // This handles reflection of negative arguments, and all our
@@ -367,7 +367,7 @@
       //
       if(remainder == 0)
       {
- return tools::pole_error<T>(BOOST_CURRENT_FUNCTION, 0, (1-x));
+ return policy::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
       }
       result = constants::pi<T>() / tan(constants::pi<T>() * remainder);
    }
@@ -404,31 +404,40 @@
 
 } // namespace detail
 
-template <class T>
+template <class T, class Policy>
 inline typename tools::promote_args<T>::type
- digamma(T x)
+ digamma(T x, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::digits == 0)
- ||
- (std::numeric_limits<T>::digits > 64),
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::precision<T, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::or_<
+ mpl::less_equal<precision_type, mpl::int_<0> >,
+ mpl::greater<precision_type, mpl::int_<64> >
+ >,
       mpl::int_<0>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits < 25),
+ typename mpl::if_<
+ mpl::less<precision_type, mpl::int_<25> >,
          mpl::int_<24>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits < 54),
+ typename mpl::if_<
+ mpl::less<precision_type, mpl::int_<54> >,
             mpl::int_<53>,
             mpl::int_<64>
>::type
>::type
>::type tag_type;
 
- return tools::checked_narrowing_cast<result_type>(detail::digamma_imp(
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::digamma_imp(
       static_cast<value_type>(x),
- static_cast<const tag_type*>(0)), BOOST_CURRENT_FUNCTION);
+ static_cast<const tag_type*>(0), pol), "boost::math::digamma<%1%>(%1%)");
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type
+ digamma(T x)
+{
+ return digamma(x, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_1.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -16,28 +16,32 @@
 
 #include <boost/math/special_functions/ellint_rf.hpp>
 #include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Elliptic integrals (complete and incomplete) of the first kind
 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
 
 namespace boost { namespace math {
 
+template <class T1, class T2, class Policy>
+typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol);
+
 namespace detail{
 
 // Elliptic integral (Legendre form) of the first kind
-template <typename T>
-T ellint_f_imp(T phi, T k)
+template <typename T, typename Policy>
+T ellint_f_imp(T phi, T k, const Policy& pol)
 {
     using namespace std;
     using namespace boost::math::tools;
     using namespace boost::math::constants;
 
+ static const char* function = "boost::math::ellint_f<%1%>(%1%,%1%)";
+
     if (abs(k) > 1)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got k = %1%, function requires |k| <= 1", k);
+ return policy::raise_domain_error<T>(function,
+ "Got k = %1%, function requires |k| <= 1", k, pol);
     }
 
     bool invert = false;
@@ -53,14 +57,14 @@
     if(phi >= tools::max_value<T>())
     {
        // Need to handle infinity as a special case:
- result = tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ result = policy::raise_overflow_error<T>(function, 0, pol);
        BOOST_MATH_INSTRUMENT_CODE(result);
     }
     else if(phi > 1 / tools::epsilon<T>())
     {
        // Phi is so large that phi%pi is necessarily zero (or garbage),
        // just return the second part of the duplication formula:
- result = 2 * phi * ellint_k_imp(k) / constants::pi<T>();
+ result = 2 * phi * ellint_k_imp(k, pol) / constants::pi<T>();
        BOOST_MATH_INSTRUMENT_CODE(result);
     }
     else
@@ -86,11 +90,11 @@
        }
        T sinp = sin(rphi);
        T cosp = cos(rphi);
- result = s * sinp * ellint_rf_imp(cosp * cosp, 1 - k * k * sinp * sinp, T(1));
+ result = s * sinp * ellint_rf_imp(cosp * cosp, 1 - k * k * sinp * sinp, T(1), pol);
        BOOST_MATH_INSTRUMENT_CODE(result);
        if(m != 0)
        {
- result += m * ellint_k_imp(k);
+ result += m * ellint_k_imp(k, pol);
           BOOST_MATH_INSTRUMENT_CODE(result);
        }
     }
@@ -98,48 +102,69 @@
 }
 
 // Complete elliptic integral (Legendre form) of the first kind
-template <typename T>
-T ellint_k_imp(T k)
+template <typename T, typename Policy>
+T ellint_k_imp(T k, const Policy& pol)
 {
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_k<%1%>(%1%)";
+
     if (abs(k) > 1)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got k = %1%, function requires |k| <= 1", k);
+ return policy::raise_domain_error<T>(function,
+ "Got k = %1%, function requires |k| <= 1", k, pol);
     }
     if (abs(k) == 1)
     {
- return overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>(function, 0, pol);
     }
 
     T x = 0;
     T y = 1 - k * k;
     T z = 1;
- T value = ellint_rf_imp(x, y, z);
+ T value = ellint_rf_imp(x, y, z, pol);
 
     return value;
 }
 
+template <typename T, typename Policy>
+inline typename tools::promote_args<T>::type ellint_1(T k, const Policy& pol, const mpl::true_&)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::ellint_k_imp(static_cast<value_type>(k), pol), "boost::math::ellint_1<%1%>(%1%)");
+}
+
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const mpl::false_&)
+{
+ return boost::math::ellint_1(k, phi, policy::policy<>());
+}
+
 }
 
 // Complete elliptic integral (Legendre form) of the first kind
 template <typename T>
 inline typename tools::promote_args<T>::type ellint_1(T k)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::ellint_k_imp(static_cast<value_type>(k)), BOOST_CURRENT_FUNCTION);
+ return ellint_1(k, policy::policy<>());
 }
 
 // Elliptic integral (Legendre form) of the first kind
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol)
+{
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::ellint_f_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::ellint_1<%1%>(%1%,%1%)");
+}
+
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi)
 {
- typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::ellint_f_imp(static_cast<value_type>(phi), static_cast<value_type>(k)), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::is_policy<T2>::type tag_type;
+ return detail::ellint_1(k, phi, tag_type());
 }
 
 }} // namespaces

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_2.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_2.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_2.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -17,20 +17,24 @@
 #include <boost/math/special_functions/ellint_rf.hpp>
 #include <boost/math/special_functions/ellint_rd.hpp>
 #include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Elliptic integrals (complete and incomplete) of the second kind
 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
 
-namespace boost { namespace math { namespace detail{
+namespace boost { namespace math {
+
+template <class T1, class T2, class Policy>
+typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol);
+
+namespace detail{
 
-template <typename T>
-T ellint_e_imp(T k);
+template <typename T, typename Policy>
+T ellint_e_imp(T k, const Policy& pol);
 
 // Elliptic integral (Legendre form) of the second kind
-template <typename T>
-T ellint_e_imp(T phi, T k)
+template <typename T, typename Policy>
+T ellint_e_imp(T phi, T k, const Policy& pol)
 {
     using namespace std;
     using namespace boost::math::tools;
@@ -48,13 +52,13 @@
     if(phi >= tools::max_value<T>())
     {
        // Need to handle infinity as a special case:
- result = tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ result = policy::raise_overflow_error<T>("boost::math::ellint_e<%1%>(%1%,%1%)", 0, pol);
     }
     else if(phi > 1 / tools::epsilon<T>())
     {
        // Phi is so large that phi%pi is necessarily zero (or garbage),
        // just return the second part of the duplication formula:
- result = 2 * phi * ellint_e_imp(k) / constants::pi<T>();
+ result = 2 * phi * ellint_e_imp(k, pol) / constants::pi<T>();
     }
     else
     {
@@ -80,24 +84,24 @@
        T t = k * k * sinp * sinp;
        T y = 1 - t;
        T z = 1;
- result = s * sinp * (ellint_rf_imp(x, y, z) - t * ellint_rd_imp(x, y, z) / 3);
+ result = s * sinp * (ellint_rf_imp(x, y, z, pol) - t * ellint_rd_imp(x, y, z, pol) / 3);
        if(m != 0)
- result += m * ellint_e_imp(k);
+ result += m * ellint_e_imp(k, pol);
     }
     return invert ? -result : result;
 }
 
 // Complete elliptic integral (Legendre form) of the second kind
-template <typename T>
-T ellint_e_imp(T k)
+template <typename T, typename Policy>
+T ellint_e_imp(T k, const Policy& pol)
 {
     using namespace std;
     using namespace boost::math::tools;
 
     if (abs(k) > 1)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got k = %1%, function requires |k| <= 1", k);
+ return policy::raise_domain_error<T>("boost::math::ellint_e<%1%>(%1%)",
+ "Got k = %1%, function requires |k| <= 1", k, pol);
     }
     if (abs(k) == 1)
     {
@@ -108,29 +112,49 @@
     T t = k * k;
     T y = 1 - t;
     T z = 1;
- T value = ellint_rf_imp(x, y, z) - t * ellint_rd_imp(x, y, z) / 3;
+ T value = ellint_rf_imp(x, y, z, pol) - t * ellint_rd_imp(x, y, z, pol) / 3;
 
     return value;
 }
 
+template <typename T, typename Policy>
+inline typename tools::promote_args<T>::type ellint_2(T k, const Policy& pol, const mpl::true_&)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::ellint_e_imp(static_cast<value_type>(k), pol), "boost::math::ellint_2<%1%>(%1%)");
+}
+
+// Elliptic integral (Legendre form) of the second kind
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const mpl::false_&)
+{
+ return boost::math::ellint_2(k, phi, policy::policy<>());
+}
+
 } // detail
 
 // Complete elliptic integral (Legendre form) of the second kind
 template <typename T>
 inline typename tools::promote_args<T>::type ellint_2(T k)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::ellint_e_imp(static_cast<value_type>(k)), BOOST_CURRENT_FUNCTION);
+ return ellint_2(k, policy::policy<>());
 }
 
 // Elliptic integral (Legendre form) of the second kind
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi)
 {
+ typedef typename policy::is_policy<T2>::type tag_type;
+ return detail::ellint_2(k, phi, tag_type());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol)
+{
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::ellint_e_imp(static_cast<value_type>(phi), static_cast<value_type>(k)), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::ellint_e_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::ellint_2<%1%>(%1%,%1%)");
 }
 
 }} // namespaces

Modified: sandbox/math_toolkit/boost/math/special_functions/ellint_3.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/ellint_3.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/ellint_3.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -20,19 +20,24 @@
 #include <boost/math/special_functions/ellint_2.hpp>
 #include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/constants/constants.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Elliptic integrals (complete and incomplete) of the third kind
 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
 
-namespace boost { namespace math { namespace detail{
+namespace boost { namespace math {
+
+template <class T1, class T2, class T3, class Policy>
+typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol);
+
+namespace detail{
 
-template <typename T>
-T ellint_pi_imp(T v, T k, T vc);
+template <typename T, typename Policy>
+T ellint_pi_imp(T v, T k, T vc, const Policy& pol);
 
 // Elliptic integral (Legendre form) of the third kind
-template <typename T>
-T ellint_pi_imp(T v, T phi, T k, T vc)
+template <typename T, typename Policy>
+T ellint_pi_imp(T v, T phi, T k, T vc, const Policy& pol)
 {
     // Note vc = 1-v presumably without cancellation error.
     T value, x, y, z, p, t;
@@ -41,10 +46,12 @@
     using namespace boost::math::tools;
     using namespace boost::math::constants;
 
+ static const char* function = "boost::math::ellint_3<%1%>(%1%,%1%,%1%)";
+
     if (abs(k) > 1)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got k = %1%, function requires |k| <= 1", k);
+ return policy::raise_domain_error<T>(function,
+ "Got k = %1%, function requires |k| <= 1", k, pol);
     }
 
     T sphi = sin(fabs(phi));
@@ -52,15 +59,15 @@
     if(v > 1 / (sphi * sphi))
     {
         // Complex result is a domain error:
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got v = %1%, but result is complex for v > 1 / sin^2(phi)", v);
+ return policy::raise_domain_error<T>(function,
+ "Got v = %1%, but result is complex for v > 1 / sin^2(phi)", v, pol);
     }
 
     // Special cases first:
     if(v == 0)
     {
        // A&S 17.7.18 & 19
- return (k == 0) ? phi : ellint_f_imp(phi, k);
+ return (k == 0) ? phi : ellint_f_imp(phi, k, pol);
     }
     if(phi == constants::pi<T>() / 2)
     {
@@ -71,7 +78,7 @@
        // in a T, this is a bit of a guess as to the users true
        // intent...
        //
- return ellint_pi_imp(v, k, vc);
+ return ellint_pi_imp(v, k, vc, pol);
     }
     if(k == 0)
     {
@@ -90,7 +97,7 @@
           // v > 1:
           T vcr = sqrt(-vc);
           T arg = vcr * tan(phi);
- return (boost::math::log1p(arg) - boost::math::log1p(-arg)) / (2 * vcr);
+ return (boost::math::log1p(arg, pol) - boost::math::log1p(-arg, pol)) / (2 * vcr);
        }
     }
 
@@ -106,10 +113,10 @@
        T Nm1 = (1 - k2) / (1 - v);
        T p2 = sqrt(-v * (k2 - v) / (1 - v));
        T delta = sqrt(1 - k2 * sphi * sphi);
- T result = ellint_pi_imp(N, phi, k, Nm1);
+ T result = ellint_pi_imp(N, phi, k, Nm1, pol);
 
        result *= sqrt(Nm1 * (1 - k2 / N));
- result += ellint_f_imp(phi, k) * k2 / p2;
+ result += ellint_f_imp(phi, k, pol) * k2 / p2;
        result += atan((p2/2) * sin(2 * phi) / delta);
        result /= sqrt((1 - v) * (1 - k2 / v));
        return result;
@@ -162,14 +169,14 @@
     if(fabs(phi) > 1 / tools::epsilon<T>())
     {
        if(v > 1)
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v);
+ return policy::raise_domain_error<T>(
+ function,
+ "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v, pol);
        //
        // Phi is so large that phi%pi is necessarily zero (or garbage),
        // just return the second part of the duplication formula:
        //
- value = 2 * fabs(phi) * ellint_pi_imp(v, k, vc) / constants::pi<T>();
+ value = 2 * fabs(phi) * ellint_pi_imp(v, k, vc, pol) / constants::pi<T>();
     }
     else
     {
@@ -189,9 +196,9 @@
           // The region with v > 1 and phi outside [0, pi/2] is
           // currently unsupported:
           //
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
- "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v);
+ return policy::raise_domain_error<T>(
+ function,
+ "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v, pol);
        }
        T sinp = sin(rphi);
        T cosp = cos(rphi);
@@ -203,9 +210,9 @@
            p = 1 - v * t;
        else
            p = x + vc * t;
- value = sign * sinp * (ellint_rf_imp(x, y, z) + v * t * ellint_rj_imp(x, y, z, p) / 3);
+ value = sign * sinp * (ellint_rf_imp(x, y, z, pol) + v * t * ellint_rj_imp(x, y, z, p, pol) / 3);
        if(m > 0)
- value += m * ellint_pi_imp(v, k, vc);
+ value += m * ellint_pi_imp(v, k, vc, pol);
     }
 
     if (phi < 0)
@@ -216,28 +223,30 @@
 }
 
 // Complete elliptic integral (Legendre form) of the third kind
-template <typename T>
-T ellint_pi_imp(T v, T k, T vc)
+template <typename T, typename Policy>
+T ellint_pi_imp(T v, T k, T vc, const Policy& pol)
 {
     // Note arg vc = 1-v, possibly without cancellation errors
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_pi<%1%>(%1%,%1%)";
+
     if (abs(k) >= 1)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got k = %1%, function requires |k| <= 1", k);
+ return policy::raise_domain_error<T>(function,
+ "Got k = %1%, function requires |k| <= 1", k, pol);
     }
     if(vc <= 0)
     {
        // Result is complex:
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Got v = %1%, function requires v < 1", v);
+ return policy::raise_domain_error<T>(function,
+ "Got v = %1%, function requires v < 1", v, pol);
     }
 
     if(v == 0)
     {
- return (k == 0) ? boost::math::constants::pi<T>() / 2 : ellint_k_imp(k);
+ return (k == 0) ? boost::math::constants::pi<T>() / 2 : ellint_k_imp(k, pol);
     }
 
     if(v < 0)
@@ -247,10 +256,10 @@
        T Nm1 = (1 - k2) / (1 - v);
        T p2 = sqrt(-v * (k2 - v) / (1 - v));
 
- T result = boost::math::detail::ellint_pi_imp(N, k, Nm1);
+ T result = boost::math::detail::ellint_pi_imp(N, k, Nm1, pol);
 
        result *= sqrt(Nm1 * (1 - k2 / N));
- result += ellint_k_imp(k) * k2 / p2;
+ result += ellint_k_imp(k, pol) * k2 / p2;
        result /= sqrt((1 - v) * (1 - k2 / v));
        return result;
     }
@@ -259,36 +268,57 @@
     T y = 1 - k * k;
     T z = 1;
     T p = vc;
- T value = ellint_rf_imp(x, y, z) + v * ellint_rj_imp(x, y, z, p) / 3;
+ T value = ellint_rf_imp(x, y, z, pol) + v * ellint_rj_imp(x, y, z, p, pol) / 3;
 
     return value;
 }
 
+template <class T1, class T2, class T3>
+inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const mpl::false_&)
+{
+ return boost::math::ellint_3(k, v, phi, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v, const Policy& pol, const mpl::true_&)
+{
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
+ detail::ellint_pi_imp(
+ static_cast<value_type>(v),
+ static_cast<value_type>(k),
+ static_cast<value_type>(1-v),
+ pol), "boost::math::ellint_3<%1%>(%1%,%1%)");
+}
+
 } // namespace detail
 
-template <class T1, class T2, class T3>
-inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi)
+template <class T1, class T2, class T3, class Policy>
+inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2, T3>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
       detail::ellint_pi_imp(
          static_cast<value_type>(v),
          static_cast<value_type>(phi),
          static_cast<value_type>(k),
- static_cast<value_type>(1-v)), BOOST_CURRENT_FUNCTION);
+ static_cast<value_type>(1-v),
+ pol), "boost::math::ellint_3<%1%>(%1%,%1%,%1%)");
+}
+
+template <class T1, class T2, class T3>
+inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi)
+{
+ typedef typename policy::is_policy<T3>::type tag_type;
+ return detail::ellint_3(k, v, phi, tag_type());
 }
 
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v)
 {
- typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
- detail::ellint_pi_imp(
- static_cast<value_type>(v),
- static_cast<value_type>(k),
- static_cast<value_type>(1-v)), BOOST_CURRENT_FUNCTION);
+ return ellint_3(k, v, policy::policy<>());
 }
 
 }} // namespaces

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,10 +13,9 @@
 #ifndef BOOST_MATH_ELLINT_RC_HPP
 #define BOOST_MATH_ELLINT_RC_HPP
 
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/tools/config.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
 
 // Carlson's degenerate elliptic integral
 // R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt
@@ -24,8 +23,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T ellint_rc_imp(T x, T y)
+template <typename T, typename Policy>
+T ellint_rc_imp(T x, T y, const Policy& pol)
 {
     T value, S, u, lambda, tolerance, prefix;
     int k;
@@ -33,15 +32,17 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)";
+
     if(x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument x must be non-negative but got %1%", x);
+ return policy::raise_domain_error<T>(function,
+ "Argument x must be non-negative but got %1%", x, pol);
     }
     if(y == 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument y must not be zero but got %1%", y);
+ return policy::raise_domain_error<T>(function,
+ "Argument y must not be zero but got %1%", y, pol);
     }
 
     // error scales as the 6th power of tolerance
@@ -73,7 +74,7 @@
         y = (y + lambda) / 4;
     }
     // Check to see if we gave up too soon:
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations(function, k, pol);
 
     // Taylor series expansion to the 5th order
     value = (1 + S * S * (T(3) / 10 + S * (T(1) / 7 + S * (T(3) / 8 + S * T(9) / 22)))) / sqrt(u);
@@ -83,16 +84,23 @@
 
 } // namespace detail
 
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- ellint_rc(T1 x, T2 y)
+ ellint_rc(T1 x, T2 y, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
       detail::ellint_rc_imp(
          static_cast<value_type>(x),
- static_cast<value_type>(y)), BOOST_CURRENT_FUNCTION);
+ static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)");
+}
+
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ ellint_rc(T1 x, T2 y)
+{
+ return ellint_rc(x, y, policy::policy<>());
 }
 
 }} // namespaces

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,8 +13,7 @@
 
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/tools/config.hpp>
-#include <boost/math/tools/error_handling.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Carlson's elliptic integral of the second kind
 // R_D(x, y, z) = R_J(x, y, z, z) = 1.5 * \int_{0}^{\infty} [(t+x)(t+y)]^{-1/2} (t+z)^{-3/2} dt
@@ -22,8 +21,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T ellint_rd_imp(T x, T y, T z)
+template <typename T, typename Policy>
+T ellint_rd_imp(T x, T y, T z, const Policy& pol)
 {
     T value, u, lambda, sigma, factor, tolerance;
     T X, Y, Z, EA, EB, EC, ED, EE, S1, S2;
@@ -32,25 +31,27 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_rd<%1%>(%1%,%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument x must be >= 0, but got %1%", x);
+ return policy::raise_domain_error<T>(function,
+ "Argument x must be >= 0, but got %1%", x, pol);
     }
     if (y < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument y must be >= 0, but got %1%", y);
+ return policy::raise_domain_error<T>(function,
+ "Argument y must be >= 0, but got %1%", y, pol);
     }
     if (z <= 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument z must be > 0, but got %1%", z);
+ return policy::raise_domain_error<T>(function,
+ "Argument z must be > 0, but got %1%", z, pol);
     }
     if (x + y == 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "At most one argument can be zero, but got, x + y = %1%", x+y);
+ return policy::raise_domain_error<T>(function,
+ "At most one argument can be zero, but got, x + y = %1%", x+y, pol);
     }
 
     // error scales as the 6th power of tolerance
@@ -78,7 +79,7 @@
         z = (z + lambda) / 4;
     }
     // Check to see if we gave up too soon:
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations(function, k, pol);
 
     // Taylor series expansion to the 5th order
     EA = X * Y;
@@ -95,17 +96,24 @@
 
 } // namespace detail
 
-template <class T1, class T2, class T3>
+template <class T1, class T2, class T3, class Policy>
 inline typename tools::promote_args<T1, T2, T3>::type
- ellint_rd(T1 x, T2 y, T3 z)
+ ellint_rd(T1 x, T2 y, T3 z, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2, T3>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
       detail::ellint_rd_imp(
          static_cast<value_type>(x),
          static_cast<value_type>(y),
- static_cast<value_type>(z)), BOOST_CURRENT_FUNCTION);
+ static_cast<value_type>(z), pol), "boost::math::ellint_rd<%1%>(%1%,%1%,%1%)");
+}
+
+template <class T1, class T2, class T3>
+inline typename tools::promote_args<T1, T2, T3>::type
+ ellint_rd(T1 x, T2 y, T3 z)
+{
+ return ellint_rd(x, y, z, policy::policy<>());
 }
 
 }} // namespaces

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -15,8 +15,7 @@
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/tools/config.hpp>
 
-#include <boost/math/tools/error_handling.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 // Carlson's elliptic integral of the first kind
 // R_F(x, y, z) = 0.5 * \int_{0}^{\infty} [(t+x)(t+y)(t+z)]^{-1/2} dt
@@ -24,8 +23,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T ellint_rf_imp(T x, T y, T z)
+template <typename T, typename Policy>
+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;
@@ -33,25 +32,27 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_rf<%1%>(%1%,%1%,%1%)";
+
     if (x < 0 || y < 0 || z < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(function,
             "domain error, all arguments must be non-negative, "
             "only sensible result is %1%.",
- std::numeric_limits<T>::quiet_NaN());
+ std::numeric_limits<T>::quiet_NaN(), pol);
     }
     if (x + y == 0 || y + z == 0 || z + x == 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(function,
             "domain error, at most one argument can be zero, "
             "only sensible result is %1%.",
- std::numeric_limits<T>::quiet_NaN());
+ std::numeric_limits<T>::quiet_NaN(), pol);
     }
 
     // Carlson scales error as the 6th power of tolerance,
     // but this seems not to work for types larger than
     // 80-bit reals, this heuristic seems to work OK:
- if(tools::digits<T>() > 64)
+ if(policy::digits<T, Policy>() > 64)
     {
       tolerance = pow(tools::epsilon<T>(), T(1)/4.25f);
       BOOST_MATH_INSTRUMENT_CODE(tolerance);
@@ -83,7 +84,7 @@
         z = (z + lambda) / 4;
     }
     // Check to see if we gave up too soon:
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations(function, k, pol);
     BOOST_MATH_INSTRUMENT_CODE(k);
 
     // Taylor series expansion to the 5th order
@@ -97,17 +98,24 @@
 
 } // namespace detail
 
-template <class T1, class T2, class T3>
+template <class T1, class T2, class T3, class Policy>
 inline typename tools::promote_args<T1, T2, T3>::type
- ellint_rf(T1 x, T2 y, T3 z)
+ ellint_rf(T1 x, T2 y, T3 z, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2, T3>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
       detail::ellint_rf_imp(
          static_cast<value_type>(x),
          static_cast<value_type>(y),
- static_cast<value_type>(z)), BOOST_CURRENT_FUNCTION);
+ static_cast<value_type>(z), pol), "boost::math::ellint_rf<%1%>(%1%,%1%,%1%)");
+}
+
+template <class T1, class T2, class T3>
+inline typename tools::promote_args<T1, T2, T3>::type
+ ellint_rf(T1 x, T2 y, T3 z)
+{
+ return ellint_rf(x, y, z, policy::policy<>());
 }
 
 }} // namespaces

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -15,8 +15,7 @@
 
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/tools/config.hpp>
-#include <boost/math/tools/error_handling.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/ellint_rc.hpp>
 
 // Carlson's elliptic integral of the third kind
@@ -25,8 +24,8 @@
 
 namespace boost { namespace math { namespace detail{
 
-template <typename T>
-T ellint_rj_imp(T x, T y, T z, T p)
+template <typename T, typename Policy>
+T ellint_rj_imp(T x, T y, T z, T p, const Policy& pol)
 {
     T value, u, lambda, alpha, beta, sigma, factor, tolerance;
     T X, Y, Z, P, EA, EB, EC, E2, E3, S1, S2, S3;
@@ -35,31 +34,33 @@
     using namespace std;
     using namespace boost::math::tools;
 
+ static const char* function = "boost::math::ellint_rj<%1%>(%1%,%1%,%1%)";
+
     if (x < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument x must be non-negative, but got x = %1%", x);
+ return policy::raise_domain_error<T>(function,
+ "Argument x must be non-negative, but got x = %1%", x, pol);
     }
     if(y < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument y must be non-negative, but got y = %1%", y);
+ return policy::raise_domain_error<T>(function,
+ "Argument y must be non-negative, but got y = %1%", y, pol);
     }
     if(z < 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument z must be non-negative, but got z = %1%", z);
+ return policy::raise_domain_error<T>(function,
+ "Argument z must be non-negative, but got z = %1%", z, pol);
     }
     if(p == 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
- "Argument p must not be zero, but got p = %1%", p);
+ return policy::raise_domain_error<T>(function,
+ "Argument p must not be zero, but got p = %1%", p, pol);
     }
     if (x + y == 0 || y + z == 0 || z + x == 0)
     {
- return domain_error<T>(BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(function,
             "At most one argument can be zero, "
- "only possible result is %1%.", std::numeric_limits<T>::quiet_NaN());
+ "only possible result is %1%.", std::numeric_limits<T>::quiet_NaN(), pol);
     }
 
     // error scales as the 6th power of tolerance
@@ -86,10 +87,10 @@
        BOOST_ASSERT(pmy >= 0);
 
        T p = pmy + y;
- value = ellint_rj(x, y, z, p);
+ value = ellint_rj(x, y, z, p, pol);
        value *= pmy;
- value -= 3 * ellint_rf(x, y, z);
- value += 3 * sqrt((x * y * z) / (x * z + p * q)) * ellint_rc(x * z + p * q, p * q);
+ value -= 3 * ellint_rf(x, y, z, pol);
+ value += 3 * sqrt((x * y * z) / (x * z + p * q)) * ellint_rc(x * z + p * q, p * q, pol);
        value /= (y + q);
        return value;
     }
@@ -116,7 +117,7 @@
         alpha = p * (sx + sy + sz) + sx * sy * sz;
         alpha *= alpha;
         beta = p * (p + lambda) * (p + lambda);
- sigma += factor * ellint_rc(alpha, beta);
+ sigma += factor * ellint_rc(alpha, beta, pol);
         factor /= 4;
         x = (x + lambda) / 4;
         y = (y + lambda) / 4;
@@ -124,7 +125,7 @@
         p = (p + lambda) / 4;
     }
     // Check to see if we gave up too soon:
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, k);
+ policy::check_series_iterations(function, k, pol);
 
     // Taylor series expansion to the 5th order
     EA = X * Y + Y * Z + Z * X;
@@ -142,18 +143,26 @@
 
 } // namespace detail
 
-template <class T1, class T2, class T3, class T4>
+template <class T1, class T2, class T3, class T4, class Policy>
 inline typename tools::promote_args<T1, T2, T3, T4>::type
- ellint_rj(T1 x, T2 y, T3 z, T4 p)
+ ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol)
 {
    typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(
       detail::ellint_rj_imp(
          static_cast<value_type>(x),
          static_cast<value_type>(y),
          static_cast<value_type>(z),
- static_cast<value_type>(p)), BOOST_CURRENT_FUNCTION);
+ static_cast<value_type>(p),
+ pol), "boost::math::ellint_rj<%1%>(%1%,%1%,%1%,%1%)");
+}
+
+template <class T1, class T2, class T3, class T4>
+inline typename tools::promote_args<T1, T2, T3, T4>::type
+ ellint_rj(T1 x, T2 y, T3 z, T4 p)
+{
+ return ellint_rj(x, y, z, p, policy::policy<>());
 }
 
 }} // namespaces

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,7 +10,7 @@
 #include <boost/math/tools/config.hpp>
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/math/tools/roots.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 namespace boost{ namespace math{
 
@@ -55,54 +55,80 @@
 {
    return (std::numeric_limits<float>::max)();
 }
-inline float erf_asymptotic_limit_N(const boost::integral_constant<int, 24>&)
+inline float erf_asymptotic_limit_N(const mpl::int_<24>&)
 {
    return 2.8F;
 }
-inline float erf_asymptotic_limit_N(const boost::integral_constant<int, 53>&)
+inline float erf_asymptotic_limit_N(const mpl::int_<53>&)
 {
    return 4.3F;
 }
-inline float erf_asymptotic_limit_N(const boost::integral_constant<int, 64>&)
+inline float erf_asymptotic_limit_N(const mpl::int_<64>&)
 {
    return 4.8F;
 }
-inline float erf_asymptotic_limit_N(const boost::integral_constant<int, 106>&)
+inline float erf_asymptotic_limit_N(const mpl::int_<106>&)
 {
    return 6.5F;
 }
-inline float erf_asymptotic_limit_N(const boost::integral_constant<int, 113>&)
+inline float erf_asymptotic_limit_N(const mpl::int_<113>&)
 {
    return 6.8F;
 }
 
-template <class T>
+template <class T, class Policy>
 inline T erf_asymptotic_limit()
 {
- return erf_asymptotic_limit_N(boost::integral_constant<int, std::numeric_limits<T>::digits>());
+ typedef typename policy::precision<T, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<24> >,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<0> >,
+ mpl::int_<0>,
+ mpl::int_<24>
+ >::type,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<53> >,
+ mpl::int_<53>,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<64> >,
+ mpl::int_<64>,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<106> >,
+ mpl::int_<106>,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<113> >,
+ mpl::int_<113>,
+ mpl::int_<0>
+ >::type
+ >::type
+ >::type
+ >::type
+ >::type tag_type;
+ return erf_asymptotic_limit_N(tag_type());
 }
 
-template <class T, class L, class Tag>
-T erf_imp(T z, bool invert, const L& l, const Tag& t)
+template <class T, class Policy, class Tag>
+T erf_imp(T z, bool invert, const Policy& pol, const Tag& t)
 {
    using namespace std;
 
    if(z < 0)
    {
       if(!invert)
- return -erf_imp(-z, invert, l, t);
+ return -erf_imp(-z, invert, pol, t);
       else
- return 1 + erf_imp(-z, false, l, t);
+ return 1 + erf_imp(-z, false, pol, t);
    }
 
    T result;
 
- if(!invert && (z > detail::erf_asymptotic_limit<T>()))
+ 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;
- result = boost::math::tools::sum_series(s, boost::math::tools::digits<T>(), max_iter, 1);
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ result = boost::math::tools::sum_series(s, policy::digits<T, Policy>(), max_iter, 1);
+ policy::check_series_iterations("boost::math::erf<%1%>(%1%, %1%)", max_iter, pol);
    }
    else
    {
@@ -113,13 +139,13 @@
          result = z * exp(-x);
          result /= sqrt(boost::math::constants::pi<T>());
          if(result != 0)
- result *= 2 * detail::lower_gamma_series(T(0.5f), x, boost::math::tools::digits<T>());
+ result *= 2 * detail::lower_gamma_series(T(0.5f), x, pol);
       }
       else if(x < 1.1f)
       {
          // Compute Q:
          invert = !invert;
- result = tgamma_small_upper_part(T(0.5f), x, l);
+ result = tgamma_small_upper_part(T(0.5f), x, pol);
          result /= sqrt(boost::math::constants::pi<T>());
       }
       else
@@ -128,7 +154,7 @@
          invert = !invert;
          result = z * exp(-x);
          result /= sqrt(boost::math::constants::pi<T>());
- result *= upper_gamma_fraction(T(0.5f), x, tools::digits<T>());
+ result *= upper_gamma_fraction(T(0.5f), x, policy::digits<T, Policy>());
       }
    }
    if(invert)
@@ -136,19 +162,19 @@
    return result;
 }
 
-template <class T, class L>
-T erf_imp(T z, bool invert, const L& l, const mpl::int_<53>& t)
+template <class T, class Policy>
+T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<53>& t)
 {
    using namespace std;
 
    if(z < 0)
    {
       if(!invert)
- return -erf_imp(-z, invert, l, t);
+ return -erf_imp(-z, invert, pol, t);
       else if(z < -0.5)
- return 2 - erf_imp(-z, invert, l, t);
+ return 2 - erf_imp(-z, invert, pol, t);
       else
- return 1 + erf_imp(-z, false, l, t);
+ return 1 + erf_imp(-z, false, pol, t);
    }
 
    T result;
@@ -169,12 +195,12 @@
       }
       else if(z < 1e-10)
       {
- result = z * 1.125 + z * 0.003379167095512573896158903121545171688;
+ result = z * 1.125 + z * 0.003379167095512573896158903121545171688L;
       }
       else
       {
- static const T n[7] = { 0.00337916709551257778174, -0.000147024115786688745475, -0.37463022236812520164, 0.0163061594494816999803, -0.0534354147807331748737, 0.00161898096813581982844, -0.0059528010489182840404 };
- static const T d[7] = { 1, -0.0435089806536379531594, 0.442761965043509204727, -0.017375974533016704678, 0.0772756490303260060769, -0.00210552465858669941879, 0.00544772980263244037286 };
+ static const T n[7] = { 0.00337916709551257778174L, -0.000147024115786688745475L, -0.37463022236812520164L, 0.0163061594494816999803L, -0.0534354147807331748737L, 0.00161898096813581982844L, -0.0059528010489182840404L };
+ static const T d[7] = { 1, -0.0435089806536379531594L, 0.442761965043509204727L, -0.017375974533016704678L, 0.0772756490303260060769L, -0.00210552465858669941879L, 0.00544772980263244037286L };
          result = z * 1.125 + z * tools::evaluate_polynomial(n, z) / tools::evaluate_polynomial(d, z);
       }
    }
@@ -188,8 +214,8 @@
       if(z < 0.75)
       {
          // Worst case absolute error found: 8.554649561e-018
- static const T n[5] = { -0.0361790390718262468222, 0.301888464724047222196, 0.201731143672633894981, 0.0659353268087389983319, 0.00721876720062364930761 };
- static const T d[6] = { 1, 1.58814245739127341535, 0.99354580430196422336, 0.291753007176902027213, 0.033994791234913855515, -0.000104234653166533504303 };
+ static const T n[5] = { -0.0361790390718262468222L, 0.301888464724047222196L, 0.201731143672633894981L, 0.0659353268087389983319L, 0.00721876720062364930761L };
+ static const T d[6] = { 1, 1.58814245739127341535L, 0.99354580430196422336L, 0.291753007176902027213L, 0.033994791234913855515L, -0.000104234653166533504303L };
          static const float f0 = 0.3440242112F;
          r = tools::evaluate_polynomial(n, z - 0.5) / tools::evaluate_polynomial(d, z - 0.5);
          b = f0;
@@ -197,8 +223,8 @@
       else if(z < 1.25)
       {
          // Worst case absolute error found: 6.50251514e-018
- static const T n[6] = { -0.039787689261113685983, 0.160309168830518003303, 0.163049978514596540313, 0.0710685660158400750009, 0.01497188097404877543, 0.00130080628375002584279 };
- static const T d[6] = { 1, 1.77564880074171280407, 1.31438791181040008779, 0.509359151038517059748, 0.103958527905812829559, 0.00901292460643094469406 };
+ static const T n[6] = { -0.039787689261113685983L, 0.160309168830518003303L, 0.163049978514596540313L, 0.0710685660158400750009L, 0.01497188097404877543L, 0.00130080628375002584279L };
+ static const T d[6] = { 1, 1.77564880074171280407L, 1.31438791181040008779L, 0.509359151038517059748L, 0.103958527905812829559L, 0.00901292460643094469406L };
          static const float f0 = 0.419990927F;
          r = tools::evaluate_polynomial(n, z - 0.75) / tools::evaluate_polynomial(d, z - 0.75);
          b = f0;
@@ -206,8 +232,8 @@
       else if(z < 2.25)
       {
          // Worst case absolute error found: 1.132743504e-017
- static const T n[6] = { -0.0300838560557949724172, 0.0592886319615167248092, 0.0622294724048409148736, 0.0248575228109427909578, 0.00463781847004901844581, 0.000347305179334822548368 };
- static const T d[7] = { 1, 1.57915060645728571344, 1.03342495188878679417, 0.35158678814344218974, 0.062469256580984456783, 0.00466640448020624599948, 0.290106403940303572448e-6 };
+ static const T n[6] = { -0.0300838560557949724172L, 0.0592886319615167248092L, 0.0622294724048409148736L, 0.0248575228109427909578L, 0.00463781847004901844581L, 0.000347305179334822548368L };
+ static const T d[7] = { 1, 1.57915060645728571344L, 1.03342495188878679417L, 0.35158678814344218974L, 0.062469256580984456783L, 0.00466640448020624599948L, 0.290106403940303572448e-6L };
          static const float f0 = 0.4898625016F;
          r = tools::evaluate_polynomial(n, z - 1.25) / tools::evaluate_polynomial(d, z - 1.25);
          b = f0;
@@ -215,8 +241,8 @@
       else if(z < 3.5)
       {
          // Worst case absolute error found: 3.446364609e-018
- static const T n[6] = { -0.0117907570137227857015, 0.0162667227692515660221, 0.0175329212378413544794, 0.00620897681269247137578, 0.000986614895094589251706, 0.601354618401624353425e-4 };
- static const T d[6] = { 1, 1.33374851361555383557, 0.73227756904205983415, 0.207410266363727673685, 0.0304034048466731110163, 0.00185296959991832048613 };
+ static const T n[6] = { -0.0117907570137227857015L, 0.0162667227692515660221L, 0.0175329212378413544794L, 0.00620897681269247137578L, 0.000986614895094589251706L, 0.601354618401624353425e-4L };
+ static const T d[6] = { 1, 1.33374851361555383557L, 0.73227756904205983415L, 0.207410266363727673685L, 0.0304034048466731110163L, 0.00185296959991832048613L };
          static const float f0 = 0.5317370892F;
          r = tools::evaluate_polynomial(n, z - 2.25) / tools::evaluate_polynomial(d, z - 2.25);
          b = f0;
@@ -224,8 +250,8 @@
       else if(z < 5.5)
       {
          // Worst case absolute error found: 1.579588208e-018
- static const T n[6] = { -0.00588219091116732271979, 0.00434428684527812140098, 0.00466899990542371512895, 0.00139937567253199794533, 0.000179205902444982389766, 0.845033527560949509345e-5 };
- static const T d[6] = { 1, 1.07389345953392962127, 0.470965611895885060643, 0.105594730223366124873, 0.0121252833787344059719, 0.000571755036133730341579 };
+ static const T n[6] = { -0.00588219091116732271979L, 0.00434428684527812140098L, 0.00466899990542371512895L, 0.00139937567253199794533L, 0.000179205902444982389766L, 0.845033527560949509345e-5L };
+ static const T d[6] = { 1, 1.07389345953392962127L, 0.470965611895885060643L, 0.105594730223366124873L, 0.0121252833787344059719L, 0.000571755036133730341579L };
          static const float f0 = 0.5494099855F;
          r = tools::evaluate_polynomial(n, z - 3.5) / tools::evaluate_polynomial(d, z - 3.5);
          b = f0;
@@ -233,8 +259,8 @@
       else if(z < 9)
       {
          // Worst case absolute error found: 1.410768708e-017
- static const T n[5] = { -0.00273864253749621265032, 0.0013089921066773026803, 0.000775841526778089659703, 0.000110909476102006410909, 0.472577590124068298534e-5 };
- static const T d[6] = { 1, 0.650694792327863647878, 0.161126734432670927888, 0.0180081468446110640846, 0.000767341359508884026192, -0.287636719206664167616e-9 };
+ static const T n[5] = { -0.00273864253749621265032L, 0.0013089921066773026803L, 0.000775841526778089659703L, 0.000110909476102006410909L, 0.472577590124068298534e-5L };
+ static const T d[6] = { 1, 0.650694792327863647878L, 0.161126734432670927888L, 0.0180081468446110640846L, 0.000767341359508884026192L, -0.287636719206664167616e-9L };
          static const float f0 = 0.5580308437F;
          r = tools::evaluate_polynomial(n, z - 5.5) / tools::evaluate_polynomial(d, z - 5.5);
          b = f0;
@@ -242,8 +268,8 @@
       else if(z < 14)
       {
          // Worst case absolute error found: 1.458310511e-018
- static const T n[5] = { -0.000995856413171151859346, 0.000320252910249376187643, 0.000129085624923151780987, 0.121577881306587454509e-4, 0.33293110334156470348e-6 };
- static const T d[5] = { 1, 0.428034987547594828954, 0.0692297359775940896439, 0.00501515176145997560701, 0.00013733589151338416322 };
+ static const T n[5] = { -0.000995856413171151859346L, 0.000320252910249376187643L, 0.000129085624923151780987L, 0.121577881306587454509e-4L, 0.33293110334156470348e-6L };
+ static const T d[5] = { 1, 0.428034987547594828954L, 0.0692297359775940896439L, 0.00501515176145997560701L, 0.00013733589151338416322L };
          static const float f0 = 0.5617653728F;
          r = tools::evaluate_polynomial(n, z - 9) / tools::evaluate_polynomial(d, z - 9);
          b = f0;
@@ -251,8 +277,8 @@
       else if(z < 21)
       {
          // Worst case absolute error found: 1.08182873e-019
- static const T n[5] = { -0.000395463268432048215535, 0.91155953112698182321e-4, 0.237451641259281193813e-4, 0.145759953022524466816e-5, 0.259395907606548998142e-7 };
- static const T d[5] = { 1, 0.281604524251560309285, 0.0298468482900092392397, 0.00141114575715338885136, 0.251128951158576064819e-4 };
+ static const T n[5] = { -0.000395463268432048215535L, 0.91155953112698182321e-4L, 0.237451641259281193813e-4L, 0.145759953022524466816e-5L, 0.259395907606548998142e-7L };
+ static const T d[5] = { 1, 0.281604524251560309285L, 0.0298468482900092392397L, 0.00141114575715338885136L, 0.251128951158576064819e-4L };
          static const float f0 = 0.5631566644F;
          r = tools::evaluate_polynomial(n, z - 14) / tools::evaluate_polynomial(d, z - 14);
          b = f0;
@@ -260,8 +286,8 @@
       else
       {
          // Worst case absolute error found: 7.010370259e-018
- static const T n[4] = { -0.000139182098873874523526, 0.395254617101737287826e-4, 0.376801239136290345387e-5, 0.629017242098850415839e-7 };
- static const T d[4] = { 1, 0.15077096006891495258, 0.00756136203065884121997, 0.000126226197336507576933 };
+ static const T n[4] = { -0.000139182098873874523526L, 0.395254617101737287826e-4L, 0.376801239136290345387e-5L, 0.629017242098850415839e-7L };
+ static const T d[4] = { 1, 0.15077096006891495258L, 0.00756136203065884121997L, 0.000126226197336507576933L };
          static const float f0 = 0.5636912584F;
          r = tools::evaluate_polynomial(n, z - 21) / tools::evaluate_polynomial(d, z - 21);
          b = f0;
@@ -287,19 +313,19 @@
 } // template <class T, class L>T erf_imp(T z, bool invert, const L& l, const mpl::int_<53>& t)
 
 
-template <class T, class L>
-T erf_imp(T z, bool invert, const L& l, const mpl::int_<64>& t)
+template <class T, class Policy>
+T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<64>& t)
 {
    using namespace std;
 
    if(z < 0)
    {
       if(!invert)
- return -erf_imp(-z, invert, l, t);
+ return -erf_imp(-z, invert, pol, t);
       else if(z < -0.5)
- return 2 - erf_imp(-z, invert, l, t);
+ return 2 - erf_imp(-z, invert, pol, t);
       else
- return 1 + erf_imp(-z, false, l, t);
+ return 1 + erf_imp(-z, false, pol, t);
    }
 
    T result;
@@ -475,19 +501,19 @@
 } // template <class T, class L>T erf_imp(T z, bool invert, const L& l, const mpl::int_<64>& t)
 
 
-template <class T, class L>
-T erf_imp(T z, bool invert, const L& l, const mpl::int_<113>& t)
+template <class T, class Policy>
+T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<113>& t)
 {
    using namespace std;
 
    if(z < 0)
    {
       if(!invert)
- return -erf_imp(-z, invert, l, t);
+ return -erf_imp(-z, invert, pol, t);
       else if(z < -0.5)
- return 2 - erf_imp(-z, invert, l, t);
+ return 2 - erf_imp(-z, invert, pol, t);
       else
- return 1 + erf_imp(-z, false, l, t);
+ return 1 + erf_imp(-z, false, pol, t);
    }
 
    T result;
@@ -710,24 +736,30 @@
 
 } // namespace detail
 
-template <class T>
-inline typename tools::promote_args<T>::type erf(T z)
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type erf(T z, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
-
- typedef typename mpl::if_c<
- ::std::numeric_limits<result_type>::is_specialized == 0,
- mpl::int_<0>, // no numeric_limits, use generic solution
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 53,
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ typedef typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<0> >,
+ mpl::int_<0>,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<53> >,
          mpl::int_<53>, // double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 64,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<64> >,
             mpl::int_<64>, // 80-bit long double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 113,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<113> >,
                mpl::int_<113>, // 128-bit long double
                mpl::int_<0> // too many bits, use generic version.
>::type
@@ -735,31 +767,37 @@
>::type
>::type tag_type;
 
- return tools::checked_narrowing_cast<result_type>(detail::erf_imp(
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp(
       static_cast<value_type>(z),
       false,
- evaluation_type(),
- tag_type()), BOOST_CURRENT_FUNCTION);
+ forwarding_policy(),
+ tag_type()), "boost::math::erf<%1%>(%1%, %1%)");
 }
 
-template <class T>
-inline typename tools::promote_args<T>::type erfc(T z)
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type erfc(T z, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
-
- typedef typename mpl::if_c<
- ::std::numeric_limits<result_type>::is_specialized == 0,
- mpl::int_<0>, // no numeric_limits, use generic solution
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 53,
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ typedef typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<0> >,
+ mpl::int_<0>,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<53> >,
          mpl::int_<53>, // double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 64,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<64> >,
             mpl::int_<64>, // 80-bit long double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 113,
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<113> >,
                mpl::int_<113>, // 128-bit long double
                mpl::int_<0> // too many bits, use generic version.
>::type
@@ -767,11 +805,23 @@
>::type
>::type tag_type;
 
- return tools::checked_narrowing_cast<result_type>(detail::erf_imp(
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp(
       static_cast<value_type>(z),
       true,
- evaluation_type(),
- tag_type()), BOOST_CURRENT_FUNCTION);
+ forwarding_policy(),
+ tag_type()), "boost::math::erfc<%1%>(%1%, %1%)");
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type erf(T z)
+{
+ return boost::math::erf(z, policy::policy<>());
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type erfc(T z)
+{
+ return boost::math::erfc(z, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,9 +12,10 @@
 #include <boost/math/tools/config.hpp>
 #include <boost/math/tools/series.hpp>
 #include <boost/math/tools/precision.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/tools/rational.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
+#include <boost/mpl/less_equal.hpp>
 
 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
 # include <boost/static_assert.hpp>
@@ -64,8 +65,8 @@
 //
 // This version uses a Taylor series expansion for 0.5 > |x| > epsilon.
 //
-template <class T>
-T expm1_imp(T x, const mpl::int_<0>&)
+template <class T, class Policy>
+T expm1_imp(T x, const mpl::int_<0>&, const Policy& pol)
 {
    using namespace std;
 
@@ -77,17 +78,17 @@
    detail::expm1_series<T> s(x);
    boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- T result = tools::sum_series(s, tools::digits<T>() + 2, max_iter);
+ T result = tools::sum_series(s, policy::digits<T, Policy>(), max_iter);
 #else
    T zero = 0;
- T result = tools::sum_series(s, tools::digits<T>() + 2, max_iter, zero);
+ T result = tools::sum_series(s, policy::digits<T, Policy>(), max_iter, zero);
 #endif
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ policy::check_series_iterations("boost::math::expm1<%1%>(%1%)", max_iter, pol);
    return result;
 }
 
-template <class T>
-T expm1_imp(T x, const mpl::int_<53>&)
+template <class T, class P>
+T expm1_imp(T x, const mpl::int_<53>&, const P&)
 {
    using namespace std;
 
@@ -105,8 +106,8 @@
    return result;
 }
 
-template <class T>
-T expm1_imp(T x, const mpl::int_<64>&)
+template <class T, class P>
+T expm1_imp(T x, const mpl::int_<64>&, const P&)
 {
    using namespace std;
 
@@ -140,8 +141,8 @@
    return result;
 }
 
-template <class T>
-T expm1_imp(T x, const mpl::int_<113>&)
+template <class T, class P>
+T expm1_imp(T x, const mpl::int_<113>&, const P&)
 {
    using namespace std;
 
@@ -184,23 +185,30 @@
 
 } // namespace detail
 
-template <class T>
-inline typename tools::promote_args<T>::type expm1(T x)
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type expm1(T x, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
    typedef typename mpl::if_c<
       ::std::numeric_limits<result_type>::is_specialized == 0,
       mpl::int_<0>, // no numeric_limits, use generic solution
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 53,
+ typename mpl::if_<
+ typename mpl::less_equal<precision_type, mpl::int_<53> >::type,
          mpl::int_<53>, // double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 64,
+ typename mpl::if_<
+ typename mpl::less_equal<precision_type, mpl::int_<64> >::type,
             mpl::int_<64>, // 80-bit long double
- typename mpl::if_c<
- ::std::numeric_limits<result_type>::digits <= 113,
+ typename mpl::if_<
+ typename mpl::less_equal<precision_type, mpl::int_<113> >::type,
                mpl::int_<113>, // 128-bit long double
                mpl::int_<0> // too many bits, use generic version.
>::type
@@ -208,9 +216,32 @@
>::type
>::type tag_type;
 
- return tools::checked_narrowing_cast<result_type>(detail::expm1_imp(
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::expm1_imp(
       static_cast<value_type>(x),
- tag_type()), BOOST_CURRENT_FUNCTION);
+ tag_type(), forwarding_policy()), "boost::math::expm1<%1%>(%1%)");
+}
+
+#ifdef expm1
+# ifndef BOOST_HAS_expm1
+# define BOOST_HAS_expm1
+# endif
+# undef expm1
+#endif
+
+#ifdef BOOST_HAS_EXPM1
+# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
+inline float expm1(float x, const policy::policy<>&){ return ::expm1f(x); }
+inline long double expm1(long double x, const policy::policy<>&){ return ::expm1l(x); }
+#else
+inline float expm1(float x, const policy::policy<>&){ return ::expm1(x); }
+#endif
+inline double expm1(double x, const policy::policy<>&){ return ::expm1(x); }
+#endif
+
+template <class T>
+inline typename tools::promote_args<T>::type expm1(T x)
+{
+ return expm1(x, policy::policy<>());
 }
 
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
@@ -228,23 +259,6 @@
 }
 #endif
 
-#ifdef expm1
-# ifndef BOOST_HAS_expm1
-# define BOOST_HAS_expm1
-# endif
-# undef expm1
-#endif
-
-#ifdef BOOST_HAS_EXPM1
-# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
-inline float expm1(float x){ return ::expm1f(x); }
-inline long double expm1(long double x){ return ::expm1l(x); }
-#else
-inline float expm1(float x){ return ::expm1(x); }
-#endif
-inline double expm1(double x){ return ::expm1(x); }
-#endif
-
 } // namespace math
 } // namespace boost
 

Modified: sandbox/math_toolkit/boost/math/special_functions/factorials.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/factorials.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/factorials.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -23,19 +23,26 @@
 namespace boost { namespace math
 {
 
-template <class T>
-inline T factorial(unsigned i)
+template <class T, class Policy>
+inline T factorial(unsigned i, const Policy& pol)
 {
    using namespace std; // Aid ADL for floor.
 
    if(i <= max_factorial<T>::value)
       return unchecked_factorial<T>(i);
- T result = boost::math::tgamma(static_cast<T>(i+1));
+ T result = boost::math::tgamma(static_cast<T>(i+1), pol);
    if(result > tools::max_value<T>())
       return result; // Overflowed value! (But tgamma will have signalled the error already).
- return floor(result + 0.5);
+ return floor(result + 0.5f);
 }
 
+template <class T>
+inline T factorial(unsigned i)
+{
+ return factorial<T>(i, policy::policy<>());
+}
+/*
+// Can't have these in a policy enabled world?
 template<>
 inline float factorial<float>(unsigned i)
 {
@@ -51,9 +58,9 @@
       return unchecked_factorial<double>(i);
    return tools::overflow_error<double>(BOOST_CURRENT_FUNCTION);
 }
-
-template <class T>
-T double_factorial(unsigned i)
+*/
+template <class T, class Policy>
+T double_factorial(unsigned i, const Policy& pol)
 {
    using namespace std; // ADL lookup of std names
    if(i & 1)
@@ -68,7 +75,7 @@
       // Fallthrough: i is too large to use table lookup, try the
       // gamma function instead.
       //
- T result = boost::math::tgamma(static_cast<T>(i) / 2 + 1) / sqrt(constants::pi<T>());
+ T result = boost::math::tgamma(static_cast<T>(i) / 2 + 1, pol) / sqrt(constants::pi<T>());
       if(ldexp(tools::max_value<T>(), -static_cast<int>(i+1) / 2) > result)
          return ceil(result * ldexp(T(1), (i+1) / 2) - 0.5f);
    }
@@ -76,20 +83,26 @@
    {
       // even i:
       unsigned n = i / 2;
- T result = factorial<T>(n);
+ T result = factorial<T>(n, pol);
       if(ldexp(tools::max_value<T>(), -(int)n) > result)
          return result * ldexp(T(1), (int)n);
    }
    //
    // If we fall through to here then the result is infinite:
    //
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>("boost::math::double_factorial<%1%>(unsigned)", 0, pol);
+}
+
+template <class T>
+inline T double_factorial(unsigned i)
+{
+ return double_factorial<T>(i, policy::policy<>());
 }
 
 namespace detail{
 
-template <class T>
-T rising_factorial_imp(T x, int n)
+template <class T, class Policy>
+T rising_factorial_imp(T x, int n, const Policy& pol)
 {
    if(x < 0)
    {
@@ -108,7 +121,7 @@
          n = -n;
          inv = true;
       }
- T result = ((n&1) ? -1 : 1) * falling_factorial(-x, n);
+ T result = ((n&1) ? -1 : 1) * falling_factorial(-x, n, pol);
       if(inv)
          result = 1 / result;
       return result;
@@ -120,11 +133,11 @@
    // tgamma_delta_ratio is alreay optimised for that
    // use case:
    //
- return 1 / tgamma_delta_ratio(x, static_cast<T>(n));
+ return 1 / tgamma_delta_ratio(x, static_cast<T>(n), pol);
 }
 
-template <class T>
-inline T falling_factorial_imp(T x, unsigned n)
+template <class T, class Policy>
+inline T falling_factorial_imp(T x, unsigned n, const Policy& pol)
 {
    using namespace std; // ADL of std names
    if(x == 0)
@@ -135,7 +148,7 @@
       // For x < 0 we really have a rising factorial
       // modulo a possible change of sign:
       //
- return (n&1 ? -1 : 1) * rising_factorial(-x, n);
+ return (n&1 ? -1 : 1) * rising_factorial(-x, n, pol);
    }
    if(n == 0)
       return 1;
@@ -149,12 +162,12 @@
       unsigned n2 = tools::real_cast<unsigned>(floor(xp1));
       if(n2 == xp1)
          return 0;
- T result = tgamma_delta_ratio(xp1, -static_cast<T>(n2));
+ T result = tgamma_delta_ratio(xp1, -static_cast<T>(n2), pol);
       x -= n2;
       result *= x;
       ++n2;
       if(n2 < n)
- result *= falling_factorial(x - 1, n - n2);
+ result *= falling_factorial(x - 1, n - n2, pol);
       return result;
    }
    //
@@ -164,7 +177,7 @@
    // because tgamma_delta_ratio is alreay optimised
    // for that use case:
    //
- return tgamma_delta_ratio(x + 1, -static_cast<T>(n));
+ return tgamma_delta_ratio(x + 1, -static_cast<T>(n), pol);
 }
 
 } // namespace detail
@@ -175,7 +188,16 @@
 {
    typedef typename tools::promote_args<RT>::type result_type;
    return detail::falling_factorial_imp(
- static_cast<result_type>(x), n);
+ static_cast<result_type>(x), n, policy::policy<>());
+}
+
+template <class RT, class Policy>
+inline typename tools::promote_args<RT>::type
+ falling_factorial(RT x, unsigned n, const Policy& pol)
+{
+ typedef typename tools::promote_args<RT>::type result_type;
+ return detail::falling_factorial_imp(
+ static_cast<result_type>(x), n, pol);
 }
 
 template <class RT>
@@ -184,7 +206,16 @@
 {
    typedef typename tools::promote_args<RT>::type result_type;
    return detail::rising_factorial_imp(
- static_cast<result_type>(x), n);
+ static_cast<result_type>(x), n, policy::policy<>());
+}
+
+template <class RT, class Policy>
+inline typename tools::promote_args<RT>::type
+ rising_factorial(RT x, unsigned n, const Policy& pol)
+{
+ typedef typename tools::promote_args<RT>::type result_type;
+ return detail::rising_factorial_imp(
+ static_cast<result_type>(x), n, pol);
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/fpclassify.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/fpclassify.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/fpclassify.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,6 +11,7 @@
 #include <boost/limits.hpp>
 #include <boost/math/tools/real_cast.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
+#include <boost/math/special_functions/math_fwd.hpp>
 
 #if defined(_MSC_VER) || defined(__BORLANDC__)
 #include <float.h>
@@ -54,8 +55,6 @@
 
 namespace boost{ namespace math{
 
-#define BOOST_NO_MACRO_EXPAND /**/
-
 namespace detail{
 
 #if defined(BOOST_HAS_FPCLASSIFY) || defined(isnan)

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -23,7 +23,7 @@
 #include <boost/math/tools/precision.hpp>
 #include <boost/math/tools/real_cast.hpp>
 #include <boost/math/tools/promotion.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/special_functions/log1p.hpp>
@@ -33,8 +33,11 @@
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/math/special_functions/detail/igamma_large.hpp>
 #include <boost/math/special_functions/detail/unchecked_factorial.hpp>
+#include <boost/math/special_functions/detail/lgamma_small.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 #include <boost/assert.hpp>
+#include <boost/mpl/greater.hpp>
+#include <boost/mpl/equal_to.hpp>
 
 #include <cmath>
 #include <algorithm>
@@ -111,8 +114,8 @@
 //
 // tgamma(z), with Lanczos support:
 //
-template <class T, class L>
-T gamma_imp(T z, const L& l)
+template <class T, class Policy, class L>
+T gamma_imp(T z, const Policy& pol, const L& l)
 {
    using namespace std;
 
@@ -126,19 +129,20 @@
       b = true;
    }
 #endif
+ static const char* function = "boost::math::tgamma<%1%>(%1%)";
 
    if((z <= 0) && (floor(z) == z))
- return tools::pole_error<T>(BOOST_CURRENT_FUNCTION, "Evaluation of tgamma at a negative integer %1%.", z);
+ return policy::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol);
    if(z <= -20)
    {
- result = gamma_imp(-z, l) * sinpx(z);
+ result = gamma_imp(-z, pol, l) * sinpx(z);
       if((fabs(result) < 1) && (tools::max_value<T>() * fabs(result) < boost::math::constants::pi<T>()))
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol);
       result = -boost::math::constants::pi<T>() / result;
       if(result == 0)
- return tools::underflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too small to represent.");
+ return policy::raise_underflow_error<T>(function, "Result of tgamma is too small to represent.", pol);
       if(boost::math::fpclassify(result) == FP_SUBNORMAL)
- return tools::denorm_error<T>(result, BOOST_CURRENT_FUNCTION, "Result of tgamma is denormalized.");
+ return policy::raise_denorm_error<T>(function, "Result of tgamma is denormalized.", result, pol);
       return result;
    }
 
@@ -160,11 +164,11 @@
          // we're going to overflow unless this is done with care:
          T zgh = (z + static_cast<T>(L::g()) - boost::math::constants::half<T>());
          if(log(zgh) * z / 2 > tools::log_max_value<T>())
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol);
          T hp = pow(zgh, (z / 2) - T(0.25));
          result *= hp / exp(zgh);
          if(tools::max_value<T>() / hp < result)
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol);
          result *= hp;
       }
       else
@@ -176,491 +180,10 @@
    return result;
 }
 //
-// lgamma for small arguments:
-//
-template <class T, class L>
-T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<64>&, const L& /* l */)
-{
- // This version uses rational approximations for small
- // values of z accurate enough for 64-bit mantissas
- // (80-bit long doubles), works well for 53-bit doubles as well.
- // L is only used to select the Lanczos function.
-
- using namespace std; // for ADL of std names
- T result = 0;
- if(z < tools::epsilon<T>())
- {
- result = -log(z);
- }
- else if((zm1 == 0) || (zm2 == 0))
- {
- // nothing to do, result is zero....
- }
- else if(z > 2)
- {
- //
- // Begin by performing argument reduction until
- // z is in [2,3):
- //
- if(z >= 3)
- {
- do
- {
- z -= 1;
- zm2 -= 1;
- result += log(z);
- }while(z >= 3);
- // Update zm2, we need it below:
- zm2 = z - 2;
- }
-
- //
- // Use the following form:
- //
- // lgamma(z) = (z-2)(z+1)(Y + R(z-2))
- //
- // where R(z-2) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // R(z-2) has the following properties:
- //
- // At double: Max error found: 4.231e-18
- // At long double: Max error found: 1.987e-21
- // Maximum Deviation Found (approximation error): 5.900e-24
- //
- static const T P[] = {
- static_cast<T>(-0.180355685678449379109e-1L),
- static_cast<T>(0.25126649619989678683e-1L),
- static_cast<T>(0.494103151567532234274e-1L),
- static_cast<T>(0.172491608709613993966e-1L),
- static_cast<T>(-0.259453563205438108893e-3L),
- static_cast<T>(-0.541009869215204396339e-3L),
- static_cast<T>(-0.324588649825948492091e-4L)
- };
- static const T Q[] = {
- static_cast<T>(0.1e1),
- static_cast<T>(0.196202987197795200688e1L),
- static_cast<T>(0.148019669424231326694e1L),
- static_cast<T>(0.541391432071720958364e0L),
- static_cast<T>(0.988504251128010129477e-1L),
- static_cast<T>(0.82130967464889339326e-2L),
- static_cast<T>(0.224936291922115757597e-3L),
- static_cast<T>(-0.223352763208617092964e-6L)
- };
-
- static const float Y = 0.158963680267333984375e0f;
-
- T r = zm2 * (z + 1);
- T R = tools::evaluate_polynomial(P, zm2);
- R /= tools::evaluate_polynomial(Q, zm2);
-
- result += r * Y + r * R;
- }
- else
- {
- //
- // If z is less than 1 use recurrance to shift to
- // z in the interval [1,2]:
- //
- if(z < 1)
- {
- result += -log(z);
- zm2 = zm1;
- zm1 = z;
- z += 1;
- }
- //
- // Two approximations, on for z in [1,1.5] and
- // one for z in [1.5,2]:
- //
- if(z <= 1.5)
- {
- //
- // Use the following form:
- //
- // lgamma(z) = (z-1)(z-2)(Y + R(z-1))
- //
- // where R(z-1) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // R(z-1) has the following properties:
- //
- // At double precision: Max error found: 1.230011e-17
- // At 80-bit long double precision: Max error found: 5.631355e-21
- // Maximum Deviation Found: 3.139e-021
- // Expected Error Term: 3.139e-021
-
- //
- static const float Y = 0.52815341949462890625f;
-
- static const T P[] = {
- static_cast<T>(0.490622454069039543534e-1L),
- static_cast<T>(-0.969117530159521214579e-1L),
- static_cast<T>(-0.414983358359495381969e0L),
- static_cast<T>(-0.406567124211938417342e0L),
- static_cast<T>(-0.158413586390692192217e0L),
- static_cast<T>(-0.240149820648571559892e-1L),
- static_cast<T>(-0.100346687696279557415e-2L)
- };
- static const T Q[] = {
- static_cast<T>(0.1e1L),
- static_cast<T>(0.302349829846463038743e1L),
- static_cast<T>(0.348739585360723852576e1L),
- static_cast<T>(0.191415588274426679201e1L),
- static_cast<T>(0.507137738614363510846e0L),
- static_cast<T>(0.577039722690451849648e-1L),
- static_cast<T>(0.195768102601107189171e-2L)
- };
-
- T r = tools::evaluate_polynomial(P, zm1) / tools::evaluate_polynomial(Q, zm1);
- T prefix = zm1 * zm2;
-
- result += prefix * Y + prefix * r;
- }
- else
- {
- //
- // Use the following form:
- //
- // lgamma(z) = (2-z)(1-z)(Y + R(2-z))
- //
- // where R(2-z) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // R(2-z) has the following properties:
- //
- // At double precision, max error found: 1.797565e-17
- // At 80-bit long double precision, max error found: 9.306419e-21
- // Maximum Deviation Found: 2.151e-021
- // Expected Error Term: 2.150e-021
- //
- static const float Y = 0.452017307281494140625f;
-
- static const T P[] = {
- static_cast<T>(-0.292329721830270012337e-1L),
- static_cast<T>(0.144216267757192309184e0L),
- static_cast<T>(-0.142440390738631274135e0L),
- static_cast<T>(0.542809694055053558157e-1L),
- static_cast<T>(-0.850535976868336437746e-2L),
- static_cast<T>(0.431171342679297331241e-3L)
- };
- static const T Q[] = {
- static_cast<T>(0.1e1),
- static_cast<T>(-0.150169356054485044494e1L),
- static_cast<T>(0.846973248876495016101e0L),
- static_cast<T>(-0.220095151814995745555e0L),
- static_cast<T>(0.25582797155975869989e-1L),
- static_cast<T>(-0.100666795539143372762e-2L),
- static_cast<T>(-0.827193521891290553639e-6L)
- };
- T r = zm2 * zm1;
- T R = tools::evaluate_polynomial(P, -zm2) / tools::evaluate_polynomial(Q, -zm2);
-
- result += r * Y + r * R;
- }
- }
- return result;
-}
-template <class T, class L>
-T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<113>&, const L& /* l */)
-{
- //
- // This version uses rational approximations for small
- // values of z accurate enough for 113-bit mantissas
- // (128-bit long doubles).
- //
- using namespace std; // for ADL of std names
- T result = 0;
- if(z < tools::epsilon<T>())
- {
- result = -log(z);
- }
- else if((zm1 == 0) || (zm2 == 0))
- {
- // nothing to do, result is zero....
- }
- else if(z > 2)
- {
- //
- // Begin by performing argument reduction until
- // z is in [2,3):
- //
- if(z >= 3)
- {
- do
- {
- z -= 1;
- result += log(z);
- }while(z >= 3);
- zm2 = z - 2;
- }
-
- //
- // Use the following form:
- //
- // lgamma(z) = (z-2)(z+1)(Y + R(z-2))
- //
- // where R(z-2) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // Maximum Deviation Found (approximation error) 3.73e-37
-
- static const T P[] = {
- -0.018035568567844937910504030027467476655L,
- 0.013841458273109517271750705401202404195L,
- 0.062031842739486600078866923383017722399L,
- 0.052518418329052161202007865149435256093L,
- 0.01881718142472784129191838493267755758L,
- 0.0025104830367021839316463675028524702846L,
- -0.00021043176101831873281848891452678568311L,
- -0.00010249622350908722793327719494037981166L,
- -0.11381479670982006841716879074288176994e-4L,
- -0.49999811718089980992888533630523892389e-6L,
- -0.70529798686542184668416911331718963364e-8L
- };
- static const T Q[] = {
- 1L,
- 2.5877485070422317542808137697939233685L,
- 2.8797959228352591788629602533153837126L,
- 1.8030885955284082026405495275461180977L,
- 0.69774331297747390169238306148355428436L,
- 0.17261566063277623942044077039756583802L,
- 0.02729301254544230229429621192443000121L,
- 0.0026776425891195270663133581960016620433L,
- 0.00015244249160486584591370355730402168106L,
- 0.43997034032479866020546814475414346627e-5L,
- 0.46295080708455613044541885534408170934e-7L,
- -0.93326638207459533682980757982834180952e-11L,
- 0.42316456553164995177177407325292867513e-13L
- };
-
- T R = tools::evaluate_polynomial(P, zm2);
- R /= tools::evaluate_polynomial(Q, zm2);
-
- static const float Y = 0.158963680267333984375F;
-
- T r = zm2 * (z + 1);
-
- result += r * Y + r * R;
- }
- else
- {
- //
- // If z is less than 1 use recurrance to shift to
- // z in the interval [1,2]:
- //
- if(z < 1)
- {
- result += -log(z);
- zm2 = zm1;
- zm1 = z;
- z += 1;
- }
- //
- // Three approximations, on for z in [1,1.35], [1.35,1.625] and [1.625,1]
- //
- if(z <= 1.35)
- {
- //
- // Use the following form:
- //
- // lgamma(z) = (z-1)(z-2)(Y + R(z-1))
- //
- // where R(z-1) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // R(z-1) has the following properties:
- //
- // Maximum Deviation Found (approximation error) 1.659e-36
- // Expected Error Term (theoretical error) 1.343e-36
- // Max error found at 128-bit long double precision 1.007e-35
- //
- static const float Y = 0.54076099395751953125f;
-
- static const T P[] = {
- 0.036454670944013329356512090082402429697L,
- -0.066235835556476033710068679907798799959L,
- -0.67492399795577182387312206593595565371L,
- -1.4345555263962411429855341651960000166L,
- -1.4894319559821365820516771951249649563L,
- -0.87210277668067964629483299712322411566L,
- -0.29602090537771744401524080430529369136L,
- -0.0561832587517836908929331992218879676L,
- -0.0053236785487328044334381502530383140443L,
- -0.00018629360291358130461736386077971890789L,
- -0.10164985672213178500790406939467614498e-6L,
- 0.13680157145361387405588201461036338274e-8L
- };
- static const T Q[] = {
- 1,
- 4.9106336261005990534095838574132225599L,
- 10.258804800866438510889341082793078432L,
- 11.88588976846826108836629960537466889L,
- 8.3455000546999704314454891036700998428L,
- 3.6428823682421746343233362007194282703L,
- 0.97465989807254572142266753052776132252L,
- 0.15121052897097822172763084966793352524L,
- 0.012017363555383555123769849654484594893L,
- 0.0003583032812720649835431669893011257277L
- };
-
- T r = tools::evaluate_polynomial(P, zm1) / tools::evaluate_polynomial(Q, zm1);
- T prefix = zm1 * zm2;
-
- result += prefix * Y + prefix * r;
- }
- else if(z <= 1.625)
- {
- //
- // Use the following form:
- //
- // lgamma(z) = (2-z)(1-z)(Y + R(2-z))
- //
- // where R(2-z) is a rational approximation optimised for
- // low absolute error - as long as it's absolute error
- // is small compared to the constant Y - then any rounding
- // error in it's computation will get wiped out.
- //
- // R(2-z) has the following properties:
- //
- // Max error found at 128-bit long double precision 9.634e-36
- // Maximum Deviation Found (approximation error) 1.538e-37
- // Expected Error Term (theoretical error) 2.350e-38
- //
- static const float Y = 0.483787059783935546875f;
-
- static const T P[] = {
- -0.017977422421608624353488126610933005432L,
- 0.18484528905298309555089509029244135703L,
- -0.40401251514859546989565001431430884082L,
- 0.40277179799147356461954182877921388182L,
- -0.21993421441282936476709677700477598816L,
- 0.069595742223850248095697771331107571011L,
- -0.012681481427699686635516772923547347328L,
- 0.0012489322866834830413292771335113136034L,
- -0.57058739515423112045108068834668269608e-4L,
- 0.8207548771933585614380644961342925976e-6L
- };
- static const T Q[] = {
- 1,
- -2.9629552288944259229543137757200262073L,
- 3.7118380799042118987185957298964772755L,
- -2.5569815272165399297600586376727357187L,
- 1.0546764918220835097855665680632153367L,
- -0.26574021300894401276478730940980810831L,
- 0.03996289731752081380552901986471233462L,
- -0.0033398680924544836817826046380586480873L,
- 0.00013288854760548251757651556792598235735L,
- -0.17194794958274081373243161848194745111e-5L
- };
- T r = zm2 * zm1;
- T R = tools::evaluate_polynomial(P, 0.625 - zm1) / tools::evaluate_polynomial(Q, 0.625 - zm1);
-
- result += r * Y + r * R;
- }
- else
- {
- //
- // Same form as above.
- //
- // Max error found (at 128-bit long double precision) 1.831e-35
- // Maximum Deviation Found (approximation error) 8.588e-36
- // Expected Error Term (theoretical error) 1.458e-36
- //
- static const float Y = 0.443811893463134765625f;
-
- static const T P[] = {
- -0.021027558364667626231512090082402429494L,
- 0.15128811104498736604523586803722368377L,
- -0.26249631480066246699388544451126410278L,
- 0.21148748610533489823742352180628489742L,
- -0.093964130697489071999873506148104370633L,
- 0.024292059227009051652542804957550866827L,
- -0.0036284453226534839926304745756906117066L,
- 0.0002939230129315195346843036254392485984L,
- -0.11088589183158123733132268042570710338e-4L,
- 0.13240510580220763969511741896361984162e-6L
- };
- static const T Q[] = {
- 1,
- -2.4240003754444040525462170802796471996L,
- 2.4868383476933178722203278602342786002L,
- -1.4047068395206343375520721509193698547L,
- 0.47583809087867443858344765659065773369L,
- -0.09865724264554556400463655444270700132L,
- 0.012238223514176587501074150988445109735L,
- -0.00084625068418239194670614419707491797097L,
- 0.2796574430456237061420839429225710602e-4L,
- -0.30202973883316730694433702165188835331e-6L
- };
- // (2 - x) * (1 - x) * (c + R(2 - x))
- T r = zm2 * zm1;
- T R = tools::evaluate_polynomial(P, -zm2) / tools::evaluate_polynomial(Q, -zm2);
-
- result += r * Y + r * R;
- }
- }
- return result;
-}
-template <class T, class L>
-T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<0>&, const L& l)
-{
- //
- // No rational approximations are available because either
- // T has no numeric_limits support (so we can't tell how
- // many digits it has), or T has more digits than we know
- // what to do with.... we do have a Lanczos approximation
- // though, and that can be used to keep errors under control.
- //
- using namespace std; // for ADL of std names
- T result = 0;
- if(z < tools::epsilon<T>())
- {
- result = -log(z);
- }
- else if(z < 0.5)
- {
- // taking the log of tgamma reduces the error, no danger of overflow here:
- result = log(gamma_imp(z, l));
- }
- else if(z >= 3)
- {
- // taking the log of tgamma reduces the error, no danger of overflow here:
- result = log(gamma_imp(z, l));
- }
- else if(z >= 1.5)
- {
- // special case near 2:
- T dz = zm2;
- result = dz * log((z + L::g() - T(0.5)) / boost::math::constants::e<T>());
- result += boost::math::log1p(dz / (L::g() + T(1.5))) * T(1.5);
- result += boost::math::log1p(L::lanczos_sum_near_2(dz));
- }
- else
- {
- // special case near 1:
- T dz = zm1;
- result = dz * log((z + L::g() - T(0.5)) / boost::math::constants::e<T>());
- result += boost::math::log1p(dz / (L::g() + T(0.5))) / 2;
- result += boost::math::log1p(L::lanczos_sum_near_1(dz));
- }
- return result;
-}
-//
 // lgamma(z) with Lanczos support:
 //
-template <class T, class L>
-T lgamma_imp(T z, const L& l, int* sign = 0)
+template <class T, class Policy, class L>
+T lgamma_imp(T z, const Policy& pol, const L& l, int* sign = 0)
 {
 #ifdef BOOST_MATH_INSTRUMENT
    static bool b = false;
@@ -673,13 +196,15 @@
 
    using namespace std;
 
+ static const char* function = "boost::math::lgamma<%1%>(%1%)";
+
    T result = 0;
    int sresult = 1;
    if(z <= 0)
    {
       // reflection formula:
       if(floor(z) == z)
- return tools::pole_error<T>(BOOST_CURRENT_FUNCTION, "Evaluation of lgamma at a negative integer %1%.", z);
+ return policy::raise_pole_error<T>(function, "Evaluation of lgamma at a negative integer %1%.", z, pol);
 
       T t = sinpx(z);
       z = -z;
@@ -691,23 +216,24 @@
       {
          sresult = -sresult;
       }
- result = log(boost::math::constants::pi<T>()) - lgamma_imp(z, l) - log(t);
+ result = log(boost::math::constants::pi<T>()) - lgamma_imp(z, pol, l) - log(t);
    }
    else if(z < 15)
    {
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 64)),
+ typedef typename policy::precision<T, Policy>::type precision_type;
+ typedef typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<64> >,
          mpl::int_<64>,
- typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 113)),
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<113> >,
             mpl::int_<113>, mpl::int_<0> >::type
>::type tag_type;
- result = lgamma_small_imp(z, z - 1, z - 2, tag_type(), l);
+ result = lgamma_small_imp(z, z - 1, z - 2, tag_type(), pol);
    }
    else if((z >= 3) && (z < 100))
    {
       // taking the log of tgamma reduces the error, no danger of overflow here:
- result = log(gamma_imp(z, l));
+ result = log(gamma_imp(z, pol, l));
    }
    else
    {
@@ -777,21 +303,22 @@
    }
 };
 
-template <class T>
-inline T lower_gamma_series(T a, T z, int bits)
+template <class T, class Policy>
+inline T lower_gamma_series(T a, T z, const Policy& pol)
 {
    // Multiply result by ((z^a) * (e^-z) / a) to get the full
    // 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;
+ int bits = policy::digits<T, Policy>();
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T zero = 0;
    T result = boost::math::tools::sum_series(s, bits, max_iter, zero);
 #else
    T result = boost::math::tools::sum_series(s, bits, max_iter);
 #endif
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ policy::check_series_iterations("boost::math::detail::lower_gamma_series<%1%>(%1%)", max_iter, pol);
    return result;
 }
 
@@ -799,22 +326,23 @@
 // Fully generic tgamma and lgamma use the incomplete partial
 // sums added together:
 //
-template <class T>
-T gamma_imp(T z, const lanczos::undefined_lanczos& l)
+template <class T, class Policy>
+T gamma_imp(T z, const Policy& pol, const lanczos::undefined_lanczos& l)
 {
+ static const char* function = "boost::math::tgamma<%1%>(%1%)";
    using namespace std;
    if((z <= 0) && (floor(z) == z))
- return tools::pole_error<T>(BOOST_CURRENT_FUNCTION, "Evaluation of tgamma at a negative integer %1%.", z);
+ return policy::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol);
    if(z <= -20)
    {
- T result = gamma_imp(-z, l) * sinpx(z);
+ T result = gamma_imp(-z, pol, l) * sinpx(z);
       if((fabs(result) < 1) && (tools::max_value<T>() * fabs(result) < boost::math::constants::pi<T>()))
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol);
       result = -boost::math::constants::pi<T>() / result;
       if(result == 0)
- return tools::underflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too small to represent.");
+ return policy::raise_underflow_error<T>(function, "Result of tgamma is too small to represent.", pol);
       if(boost::math::fpclassify(result) == FP_SUBNORMAL)
- return tools::denorm_error<T>(result, BOOST_CURRENT_FUNCTION, "Result of tgamma is denormalized.");
+ return policy::raise_denorm_error<T>(function, "Result of tgamma is denormalized.", result, pol);
       return result;
    }
    //
@@ -835,26 +363,27 @@
    else
    {
       prefix = prefix * pow(z / boost::math::constants::e<T>(), z);
- T sum = detail::lower_gamma_series(z, z, ::boost::math::tools::digits<T>()) / z;
- sum += detail::upper_gamma_fraction(z, z, ::boost::math::tools::digits<T>());
+ T sum = detail::lower_gamma_series(z, z, pol) / z;
+ sum += detail::upper_gamma_fraction(z, z, ::boost::math::policy::digits<T, Policy>());
       if(fabs(tools::max_value<T>() / prefix) < fabs(sum))
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol);
       return sum * prefix;
    }
    return prefix;
 }
 
-template <class T>
-T lgamma_imp(T z, const lanczos::undefined_lanczos&, int*sign)
+template <class T, class Policy>
+T lgamma_imp(T z, const Policy& pol, const lanczos::undefined_lanczos& l, int*sign)
 {
    using namespace std;
 
+ static const char* function = "boost::math::lgamma<%1%>(%1%)";
    T result = 0;
    int sresult = 1;
    if(z <= 0)
    {
       if(floor(z) == z)
- return tools::pole_error<T>(BOOST_CURRENT_FUNCTION, "Evaluation of tgamma at a negative integer %1%.", z);
+ return policy::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol);
       T t = detail::sinpx(z);
       z = -z;
       if(t < 0)
@@ -865,14 +394,14 @@
       {
          sresult = -sresult;
       }
- result = log(boost::math::constants::pi<T>()) - lgamma(z) - log(t);
+ result = log(boost::math::constants::pi<T>()) - lgamma_imp(z, pol, l, 0) - log(t);
    }
    else if((z != 1) && (z != 2))
    {
       T limit = (std::max)(z+1, T(10));
       T prefix = z * log(limit) - limit;
- T sum = detail::lower_gamma_series(z, limit, ::boost::math::tools::digits<T>()) / z;
- sum += detail::upper_gamma_fraction(z, limit, ::boost::math::tools::digits<T>());
+ T sum = detail::lower_gamma_series(z, limit, pol) / z;
+ sum += detail::upper_gamma_fraction(z, limit, ::boost::math::policy::digits<T, Policy>());
       result = log(sum) + prefix;
    }
    if(sign)
@@ -883,24 +412,32 @@
 // This helper calculates tgamma(dz+1)-1 without cancellation errors,
 // used by the upper incomplete gamma with z < 1:
 //
-template <class T, class Tag, class L>
-T tgammap1m1_imp(T dz, Tag const& tag, const L& l)
+template <class T, class Policy, class L>
+T tgammap1m1_imp(T dz, Policy const& pol, const L& l)
 {
    using namespace std;
 
+ typedef typename mpl::if_<
+ mpl::less_equal<typename policy::precision<T,Policy>::type, mpl::int_<64> >,
+ mpl::int_<64>,
+ typename mpl::if_<
+ mpl::less_equal<typename policy::precision<T,Policy>::type, mpl::int_<113> >,
+ mpl::int_<113>, mpl::int_<0> >::type
+ >::type tag_type;
+
    T result;
    if(dz < 0)
    {
       if(dz < -0.5)
       {
          // Best method is simply to subtract 1 from tgamma:
- result = boost::math::tgamma(1+dz) - 1;
+ result = boost::math::tgamma(1+dz, pol) - 1;
       }
       else
       {
          // Use expm1 on lgamma:
- result = boost::math::expm1(-boost::math::log1p(dz)
- + lgamma_small_imp(dz+2, dz + 1, dz, tag, l));
+ result = boost::math::expm1(-boost::math::log1p(dz, pol)
+ + lgamma_small_imp(dz+2, dz + 1, dz, tag_type(), pol));
       }
    }
    else
@@ -908,20 +445,20 @@
       if(dz < 2)
       {
          // Use expm1 on lgamma:
- result = boost::math::expm1(lgamma_small_imp(dz+1, dz, dz-1, tag, l));
+ result = boost::math::expm1(lgamma_small_imp(dz+1, dz, dz-1, tag_type(), pol), pol);
       }
       else
       {
          // Best method is simply to subtract 1 from tgamma:
- result = boost::math::tgamma(1+dz) - 1;
+ result = boost::math::tgamma(1+dz, pol) - 1;
       }
    }
 
    return result;
 }
 
-template <class T, class Tag>
-inline T tgammap1m1_imp(T dz, Tag const& /*tag*/,
+template <class T, class Policy>
+inline T tgammap1m1_imp(T dz, Policy const& pol,
                  const ::boost::math::lanczos::undefined_lanczos& l)
 {
    using namespace std; // ADL of std names
@@ -930,34 +467,20 @@
    // algebra isn't easy for the general case....
    // Start by subracting 1 from tgamma:
    //
- T result = gamma_imp(1 + dz, l) - 1;
+ T result = gamma_imp(1 + dz, pol, l) - 1;
    //
    // Test the level of cancellation error observed: we loose one bit
    // for each power of 2 the result is less than 1. If we would get
    // more bits from our most precise lgamma rational approximation,
    // then use that instead:
    //
- if((dz > -0.5) && (dz < 2) && (ldexp(1.0, boost::math::tools::digits<T>()) * fabs(result) < 1e34))
+ if((dz > -0.5) && (dz < 2) && (ldexp(1.0, boost::math::policy::digits<T, Policy>()) * fabs(result) < 1e34))
    {
- result = tgammap1m1_imp(dz, mpl::int_<113>(), boost::math::lanczos::lanczos24m113());
+ result = tgammap1m1_imp(dz, pol, boost::math::lanczos::lanczos24m113());
    }
    return result;
 }
 
-template <class T, class L>
-inline T tgammap1m1_imp(T dz, const L& l)
-{
- // Simple forwarding function.
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 64)),
- mpl::int_<64>,
- typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 113)),
- mpl::int_<113>, mpl::int_<0> >::type
- >::type tag_type;
- return tgammap1m1_imp(dz, tag_type(), l);
-}
-
 //
 // Series representation for upper fraction when z is small:
 //
@@ -985,8 +508,8 @@
 // calculate power term prefix (z^a)(e^-z) used in the non-normalised
 // incomplete gammas:
 //
-template <class T>
-T full_igamma_prefix(T a, T z)
+template <class T, class Policy>
+T full_igamma_prefix(T a, T z, const Policy& pol)
 {
    using namespace std;
 
@@ -1028,34 +551,16 @@
    // rather than before it...
    //
    if(boost::math::fpclassify(prefix) == FP_INFINITE)
- tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of incomplete gamma function is too large to represent.");
+ policy::raise_overflow_error<T>("boost::math::detail::full_igamma_prefix<%1%>(%1%, %1%)", "Result of incomplete gamma function is too large to represent.", pol);
 
    return prefix;
 }
 //
-// Helper to compute log(1+x)-x:
-//
-template <class T>
-inline T log1pmx(T x)
-{
- boost::math::detail::log1p_series<T> s(x);
- s();
- boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- T zero = 0;
- T result = boost::math::tools::sum_series(s, tools::digits<T>() + 2, max_iter, zero);
-#else
- T result = boost::math::tools::sum_series(s, tools::digits<T>() + 2, max_iter);
-#endif
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
- return result;
-}
-//
 // Compute (z^a)(e^-z)/tgamma(a)
 // most if the error occurs in this function:
 //
-template <class T, class L>
-T regularised_gamma_prefix(T a, T z, const L& l)
+template <class T, class Policy, class L>
+T regularised_gamma_prefix(T a, T z, const Policy& pol, const L& l)
 {
    using namespace std;
    T agh = a + static_cast<T>(L::g()) - T(0.5);
@@ -1076,19 +581,19 @@
       if(z <= tools::log_min_value<T>())
       {
          // Oh dear, have to use logs, should be free of cancellation errors though:
- return exp(a * log(z) - z - lgamma_imp(a, l));
+ return exp(a * log(z) - z - lgamma_imp(a, pol, l));
       }
       else
       {
          // direct calculation, no danger of overflow as gamma(a) < 1/a
          // for small a.
- return pow(z, a) * exp(-z) / gamma_imp(a, l);
+ return pow(z, a) * exp(-z) / gamma_imp(a, pol, l);
       }
    }
    else if((fabs(d*d*a) <= 100) && (a > 150))
    {
       // special case for large a and a ~ z.
- prefix = a * log1pmx(d) + z * static_cast<T>(0.5 - L::g()) / agh;
+ prefix = a * log1pmx(d, pol) + z * static_cast<T>(0.5 - L::g()) / agh;
       prefix = exp(prefix);
    }
    else
@@ -1136,14 +641,14 @@
 //
 // And again, without Lanczos support:
 //
-template <class T>
-T regularised_gamma_prefix(T a, T z, const lanczos::undefined_lanczos&)
+template <class T, class Policy>
+T regularised_gamma_prefix(T a, T z, const Policy& pol, const lanczos::undefined_lanczos&)
 {
    using namespace std;
 
    T limit = (std::max)(T(10), a);
- T sum = detail::lower_gamma_series(a, limit, ::boost::math::tools::digits<T>()) / a;
- sum += detail::upper_gamma_fraction(a, limit, ::boost::math::tools::digits<T>());
+ T sum = detail::lower_gamma_series(a, limit, pol) / a;
+ sum += detail::upper_gamma_fraction(a, limit, ::boost::math::policy::digits<T, Policy>());
 
    if(a < 10)
    {
@@ -1184,24 +689,24 @@
 //
 // Upper gamma fraction for very small a:
 //
-template <class T, class L>
-inline T tgamma_small_upper_part(T a, T x, const L& l)
+template <class T, class Policy>
+inline T tgamma_small_upper_part(T a, T x, const Policy& pol)
 {
    using namespace std; // ADL of std functions.
    //
    // Compute the full upper fraction (Q) when a is very small:
    //
- T result = tgammap1m1_imp(a, l) - powm1(x, a);
+ 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;
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    T zero = 0;
- result -= pow(x, a) * tools::sum_series(s, boost::math::tools::digits<T>(), max_iter, zero);
+ result -= pow(x, a) * tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter, zero);
 #else
- result -= pow(x, a) * tools::sum_series(s, boost::math::tools::digits<T>(), max_iter);
+ result -= pow(x, a) * tools::sum_series(s, boost::math::policy::digits<T, Policy>(), max_iter);
 #endif
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ policy::check_series_iterations("boost::math::tgamma_small_upper_part<%1%>(%1%, %1%)", max_iter, pol);
    return result;
 }
 //
@@ -1230,14 +735,14 @@
 //
 // Upper gamma fraction for half integer a:
 //
-template <class T>
-T finite_half_gamma_q(T a, T x, T* p_derivative)
+template <class T, class Policy>
+T finite_half_gamma_q(T a, T x, T* p_derivative, const Policy& pol)
 {
    //
    // Calculates normalised Q when a is a half-integer:
    //
    using namespace std;
- T e = boost::math::erfc(sqrt(x));
+ T e = boost::math::erfc(sqrt(x), pol);
    if((e != 0) && (a > 1))
    {
       T term = exp(-x) / sqrt(constants::pi<T>() * x);
@@ -1267,17 +772,20 @@
 //
 // Main incomplete gamma entry point, handles all four incomplete gamma's:
 //
-template <class T, class L>
+template <class T, class Policy>
 T gamma_incomplete_imp(T a, T x, bool normalised, bool invert,
- const L& l, T* p_derivative)
+ const Policy& pol, T* p_derivative)
 {
+ static const char* function = "boost::math::gamma_p<%1%>(%1%, %1%)";
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>(function, "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a, pol);
    if(x < 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x);
+ policy::raise_domain_error<T>(function, "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x, pol);
 
    using namespace std;
 
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
+
    T result;
 
    BOOST_ASSERT((p_derivative == 0) || (normalised == true));
@@ -1292,20 +800,20 @@
       invert = !invert;
       result = finite_gamma_q(a, x);
       if(normalised == false)
- result *= gamma_imp(a, l);
+ result *= boost::math::tgamma(a, pol);
       // TODO: calculate derivative inside sum:
       if(p_derivative)
- *p_derivative = regularised_gamma_prefix(a, x, l);
+ *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type());
    }
    else if(is_half_int && is_small_a && (x > 0.2))
    {
       // calculate Q via finite sum for half integer a:
       invert = !invert;
- result = finite_half_gamma_q(a, x, p_derivative);
+ result = finite_half_gamma_q(a, x, p_derivative, pol);
       if(normalised == false)
- result *= gamma_imp(a, l);
+ result *= boost::math::tgamma(a, pol);
       if(p_derivative && (*p_derivative == 0))
- *p_derivative = regularised_gamma_prefix(a, x, l);
+ *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type());
    }
    else if(x < 0.5)
    {
@@ -1315,21 +823,21 @@
       if(-0.4 / log(x) < a)
       {
          // Compute P:
- result = normalised ? regularised_gamma_prefix(a, x, l) : full_igamma_prefix(a, x);
+ result = normalised ? regularised_gamma_prefix(a, x, pol, lanczos_type()) : full_igamma_prefix(a, x, pol);
          if(p_derivative)
             *p_derivative = result;
          if(result != 0)
- result *= detail::lower_gamma_series(a, x, boost::math::tools::digits<T>()) / a;
+ result *= detail::lower_gamma_series(a, x, pol) / a;
       }
       else
       {
          // Compute Q:
          invert = !invert;
- result = tgamma_small_upper_part(a, x, l);
+ result = tgamma_small_upper_part(a, x, pol);
          if(normalised)
- result /= gamma_imp(a, l);
+ result /= boost::math::tgamma(a, pol);
          if(p_derivative)
- *p_derivative = regularised_gamma_prefix(a, x, l);
+ *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type());
       }
    }
    else if(x < 1.1)
@@ -1340,21 +848,21 @@
       if(x * 1.1f < a)
       {
          // Compute P:
- result = normalised ? regularised_gamma_prefix(a, x, l) : full_igamma_prefix(a, x);
+ result = normalised ? regularised_gamma_prefix(a, x, pol, lanczos_type()) : full_igamma_prefix(a, x, pol);
          if(p_derivative)
             *p_derivative = result;
          if(result != 0)
- result *= detail::lower_gamma_series(a, x, boost::math::tools::digits<T>()) / a;
+ result *= detail::lower_gamma_series(a, x, pol) / a;
       }
       else
       {
          // Compute Q:
          invert = !invert;
- result = tgamma_small_upper_part(a, x, l);
+ result = tgamma_small_upper_part(a, x, pol);
          if(normalised)
- result /= gamma_imp(a, l);
+ result /= boost::math::tgamma(a, pol);
          if(p_derivative)
- *p_derivative = regularised_gamma_prefix(a, x, l);
+ *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type());
       }
    }
    else
@@ -1368,7 +876,7 @@
       if(normalised && std::numeric_limits<T>::is_specialized && (a > 20))
       {
          T sigma = fabs((x-a)/a);
- if((a > 200) && (tools::digits<T>() <= 113))
+ if((a > 200) && (policy::digits<T, Policy>() <= 113))
          {
             //
             // This limit is chosen so that we use Temme's expansion
@@ -1381,7 +889,7 @@
             if(20 / a > sigma * sigma)
                use_temme = true;
          }
- else if(tools::digits<T>() <= 64)
+ else if(policy::digits<T, Policy>() <= 64)
          {
             // Note in this zone we can't use Temme's expansion for
             // types longer than an 80-bit real:
@@ -1400,27 +908,28 @@
          // these expansions, in that case we'll be calling
          // an empty function.
          //
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::digits == 0)
- ||
- (std::numeric_limits<T>::digits > 113),
+ typedef typename policy::precision<T, Policy>::type precision_type;
+
+ typedef typename mpl::if_<
+ mpl::or_<mpl::equal_to<precision_type, mpl::int_<0> >,
+ mpl::greater<precision_type, mpl::int_<113> > >,
             mpl::int_<0>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits <= 53),
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<53> >,
                mpl::int_<53>,
- typename mpl::if_c<
- (std::numeric_limits<T>::digits <= 64),
+ typename mpl::if_<
+ mpl::less_equal<precision_type, mpl::int_<64> >,
                   mpl::int_<64>,
                   mpl::int_<113>
>::type
>::type
>::type tag_type;
 
- result = igamma_temme_large(a, x, static_cast<tag_type const*>(0));
+ result = igamma_temme_large(a, x, pol, static_cast<tag_type const*>(0));
          if(x >= a)
             invert = !invert;
          if(p_derivative)
- *p_derivative = regularised_gamma_prefix(a, x, l);
+ *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type());
       }
       else
       {
@@ -1429,28 +938,28 @@
          //
          // Changeover here occurs at P ~ Q ~ 0.5
          //
- result = normalised ? regularised_gamma_prefix(a, x, l) : full_igamma_prefix(a, x);
+ result = normalised ? regularised_gamma_prefix(a, x, pol, lanczos_type()) : full_igamma_prefix(a, x, pol);
          if(p_derivative)
             *p_derivative = result;
          if(x < a)
          {
             // Compute P:
             if(result != 0)
- result *= detail::lower_gamma_series(a, x, boost::math::tools::digits<T>()) / a;
+ result *= detail::lower_gamma_series(a, x, pol) / a;
          }
          else
          {
             // Compute Q:
             invert = !invert;
             if(result != 0)
- result *= upper_gamma_fraction(a, x, tools::digits<T>());
+ result *= upper_gamma_fraction(a, x, policy::digits<T, Policy>());
          }
       }
    }
 
    if(invert)
    {
- T gam = normalised ? 1 : gamma_imp(a, l);
+ T gam = normalised ? 1 : boost::math::tgamma(a, pol);
       result = gam - result;
    }
    if(p_derivative)
@@ -1470,24 +979,18 @@
    return result;
 }
 
-template <class T, class L>
-inline T gamma_incomplete_imp(T a, T x, bool normalised, bool invert, const L& l)
-{
- return gamma_incomplete_imp(a, x, normalised, invert, l, static_cast<T*>(0));
-}
-
 //
 // Ratios of two gamma functions:
 //
-template <class T, class L>
-T tgamma_delta_ratio_imp_lanczos(T z, T delta, const L&)
+template <class T, class Policy, class L>
+T tgamma_delta_ratio_imp_lanczos(T z, T delta, const Policy& pol, const L&)
 {
    using namespace std;
    T zgh = z + L::g() - constants::half<T>();
    T result;
    if(fabs(delta) < 10)
    {
- result = exp((constants::half<T>() - z) * boost::math::log1p(delta / zgh));
+ result = exp((constants::half<T>() - z) * boost::math::log1p(delta / zgh, pol));
    }
    else
    {
@@ -1500,8 +1003,8 @@
 //
 // And again without Lanczos support this time:
 //
-template <class T>
-T tgamma_delta_ratio_imp_lanczos(T z, T delta, const lanczos::undefined_lanczos&)
+template <class T, class Policy>
+T tgamma_delta_ratio_imp_lanczos(T z, T delta, const Policy& pol, const lanczos::undefined_lanczos&)
 {
    using namespace std;
    //
@@ -1520,32 +1023,32 @@
    }
    if(delta < 10)
    {
- prefix *= exp(-z * boost::math::log1p(delta / z));
+ prefix *= exp(-z * boost::math::log1p(delta / z, pol));
    }
    else
    {
       prefix *= pow(z / zd, z);
    }
    prefix *= pow(constants::e<T>() / zd, delta);
- T sum = detail::lower_gamma_series(z, z, ::boost::math::tools::digits<T>()) / z;
- sum += detail::upper_gamma_fraction(z, z, ::boost::math::tools::digits<T>());
- T sumd = detail::lower_gamma_series(zd, zd, ::boost::math::tools::digits<T>()) / zd;
- sumd += detail::upper_gamma_fraction(zd, zd, ::boost::math::tools::digits<T>());
+ T sum = detail::lower_gamma_series(z, z, pol) / z;
+ sum += detail::upper_gamma_fraction(z, z, ::boost::math::policy::digits<T, Policy>());
+ T sumd = detail::lower_gamma_series(zd, zd, pol) / zd;
+ sumd += detail::upper_gamma_fraction(zd, zd, ::boost::math::policy::digits<T, Policy>());
    sum /= sumd;
    if(fabs(tools::max_value<T>() / prefix) < fabs(sum))
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION, "Result of tgamma is too large to represent.");
+ return policy::raise_overflow_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Result of tgamma is too large to represent.", pol);
    return sum * prefix;
 }
 
-template <class T, class L>
-T tgamma_delta_ratio_imp(T z, T delta, const L& l)
+template <class T, class Policy>
+T tgamma_delta_ratio_imp(T z, T delta, const Policy& pol)
 {
    using namespace std;
 
    if(z <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Gamma function ratios only implemented for positive arguments (got a=%1%).", z);
+ policy::raise_domain_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got a=%1%).", z, pol);
    if(z+delta <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Gamma function ratios only implemented for positive arguments (got b=%1%).", z+delta);
+ policy::raise_domain_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got b=%1%).", z+delta, pol);
 
    if(floor(delta) == delta)
    {
@@ -1590,35 +1093,37 @@
          }
       }
    }
- return tgamma_delta_ratio_imp_lanczos(z, delta, l);
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
+ return tgamma_delta_ratio_imp_lanczos(z, delta, pol, lanczos_type());
 }
 
-template <class T, class L>
-T gamma_p_derivative_imp(T a, T x, const L& l)
+template <class T, class Policy>
+T gamma_p_derivative_imp(T a, T x, const Policy& pol)
 {
    //
    // Usual error checks first:
    //
    if(a <= 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a);
+ policy::raise_domain_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a, pol);
    if(x < 0)
- tools::domain_error<T>(BOOST_CURRENT_FUNCTION, "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x);
+ policy::raise_domain_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x, pol);
    //
    // Now special cases:
    //
    if(x == 0)
    {
       return (a > 1) ? 0 :
- (a == 1) ? 1 : tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ (a == 1) ? 1 : policy::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", 0, pol);
    }
    //
    // Normal case:
    //
- T f1 = detail::regularised_gamma_prefix(a, x, l);
+ typedef typename lanczos::lanczos<T, Policy>::type lanczos_type;
+ T f1 = detail::regularised_gamma_prefix(a, x, pol, lanczos_type());
    if((x < 1) && (tools::max_value<T>() * x < f1))
    {
       // overflow:
- return tools::overflow_error<T>(BOOST_CURRENT_FUNCTION);
+ return policy::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", 0, pol);
    }
 
    f1 /= x;
@@ -1626,55 +1131,120 @@
    return f1;
 }
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ tgamma(T z, const Policy& pol, const mpl::true_)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::gamma_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type()), "boost::math::tgamma<%1%>(%1%)");
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma(T1 a, T2 z, const Policy& pol, const mpl::false_)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(
+ detail::gamma_incomplete_imp(static_cast<value_type>(a),
+ static_cast<value_type>(z), false, true,
+ forwarding_policy(), static_cast<value_type*>(0)), "boost::math::tgamma<%1%>(%1%, %1%)");
+}
+
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma(T1 a, T2 z, const mpl::false_ tag)
+{
+ return tgamma(a, z, policy::policy<>(), tag);
+}
+
 } // namespace detail
 
 template <class T>
 inline typename tools::promote_args<T>::type
    tgamma(T z)
 {
+ return tgamma(z, policy::policy<>());
+}
+
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ lgamma(T z, int* sign, const Policy& pol)
+{
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::gamma_imp(static_cast<value_type>(z), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::lgamma_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type(), sign), "boost::math::lgamma<%1%>(%1%)");
 }
 
 template <class T>
 inline typename tools::promote_args<T>::type
    lgamma(T z, int* sign)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::lgamma_imp(static_cast<value_type>(z), evaluation_type(), sign), BOOST_CURRENT_FUNCTION);
+ return lgamma(z, sign, policy::policy<>());
+}
+
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ lgamma(T x, const Policy& pol)
+{
+ return ::boost::math::lgamma(x, 0, pol);
 }
 
 template <class T>
 inline typename tools::promote_args<T>::type
    lgamma(T x)
 {
- BOOST_FPU_EXCEPTION_GUARD
- return ::boost::math::lgamma(x, 0);
+ return ::boost::math::lgamma(x, 0, policy::policy<>());
 }
 
-template <class T>
+template <class T, class Policy>
 inline typename tools::promote_args<T>::type
- tgamma1pm1(T z)
+ tgamma1pm1(T z, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 64)),
- mpl::int_<64>,
- typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= 113)),
- mpl::int_<113>, mpl::int_<0> >::type
- >::type tag_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
- return tools::checked_narrowing_cast<typename remove_cv<T>::type>(detail::tgammap1m1_imp(static_cast<value_type>(z), tag_type(), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ return policy::checked_narrowing_cast<typename remove_cv<result_type>::type, forwarding_policy>(detail::tgammap1m1_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type()), "boost::math::tgamma1pm1<%!%>(%1%)");
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type
+ tgamma1pm1(T z)
+{
+ return tgamma1pm1(z, policy::policy<>());
 }
 
 //
@@ -1684,95 +1254,173 @@
 inline typename tools::promote_args<T1, T2>::type
    tgamma(T1 a, T2 z)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(
- detail::gamma_incomplete_imp(static_cast<value_type>(a),
- static_cast<value_type>(z), false, true,
- evaluation_type()), BOOST_CURRENT_FUNCTION);
+ //
+ // Type T2 could be a policy object, or a value, select the
+ // right overload based on T2:
+ //
+ typedef typename policy::is_policy<T2>::type maybe_policy;
+ return detail::tgamma(a, z, maybe_policy());
+}
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma(T1 a, T2 z, const Policy& pol)
+{
+ return detail::tgamma(a, z, pol, mpl::false_());
 }
 //
 // Full lower incomplete gamma:
 //
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- tgamma_lower(T1 a, T2 z)
+ tgamma_lower(T1 a, T2 z, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(
       detail::gamma_incomplete_imp(static_cast<value_type>(a),
       static_cast<value_type>(z), false, false,
- evaluation_type()), BOOST_CURRENT_FUNCTION);
+ forwarding_policy(), static_cast<value_type*>(0)), "tgamma_lower<%1%>(%1%, %1%)");
+}
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma_lower(T1 a, T2 z)
+{
+ return tgamma_lower(a, z, policy::policy<>());
 }
 //
 // Regularised upper incomplete gamma:
 //
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- gamma_q(T1 a, T2 z)
+ gamma_q(T1 a, T2 z, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(
       detail::gamma_incomplete_imp(static_cast<value_type>(a),
       static_cast<value_type>(z), true, true,
- evaluation_type()), BOOST_CURRENT_FUNCTION);
+ forwarding_policy(), static_cast<value_type*>(0)), "gamma_q<%1%>(%1%, %1%)");
+}
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ gamma_q(T1 a, T2 z)
+{
+ return gamma_q(a, z, policy::policy<>());
 }
 //
 // Regularised lower incomplete gamma:
 //
-template <class T1, class T2>
+template <class T1, class T2, class Policy>
 inline typename tools::promote_args<T1, T2>::type
- gamma_p(T1 a, T2 z)
+ gamma_p(T1 a, T2 z, const Policy& pol)
 {
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(
       detail::gamma_incomplete_imp(static_cast<value_type>(a),
       static_cast<value_type>(z), true, false,
- evaluation_type()), BOOST_CURRENT_FUNCTION);
+ forwarding_policy(), static_cast<value_type*>(0)), "gamma_p<%1%>(%1%, %1%)");
+}
+template <class T1, class T2>
+inline typename tools::promote_args<T1, T2>::type
+ gamma_p(T1 a, T2 z)
+{
+ return gamma_p(a, z, policy::policy<>());
 }
 
 // ratios of gamma functions:
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma_delta_ratio(T1 z, T2 delta, const Policy& pol)
+{
+ BOOST_FPU_EXCEPTION_GUARD
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(z), static_cast<value_type>(delta), forwarding_policy()), "boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)");
+}
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type
    tgamma_delta_ratio(T1 z, T2 delta)
 {
- BOOST_FPU_EXCEPTION_GUARD
+ return tgamma_delta_ratio(z, delta, policy::policy<>());
+}
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ tgamma_ratio(T1 a, T2 b, const Policy& pol)
+{
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(z), static_cast<value_type>(delta), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
+
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(a), static_cast<value_type>(b) - static_cast<value_type>(a), forwarding_policy()), "boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)");
 }
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type
    tgamma_ratio(T1 a, T2 b)
 {
+ return tgamma_ratio(a, b, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ gamma_p_derivative(T1 a, T2 x, const Policy& pol)
+{
    BOOST_FPU_EXCEPTION_GUARD
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(a), static_cast<value_type>(b - a), evaluation_type()), BOOST_CURRENT_FUNCTION);
-}
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ typedef typename policy::normalise<
+ Policy,
+ policy::promote_float<false>,
+ policy::promote_double<false>,
+ policy::discrete_quantile<>,
+ policy::assert_undefined<> >::type forwarding_policy;
 
+ return policy::checked_narrowing_cast<result_type, forwarding_policy>(detail::gamma_p_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(x), forwarding_policy()), "boost::math::gamma_p_derivative<%1%>(%1%, %1%)");
+}
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type
    gamma_p_derivative(T1 a, T2 x)
 {
- BOOST_FPU_EXCEPTION_GUARD
- typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename lanczos::lanczos_traits<result_type>::value_type value_type;
- typedef typename lanczos::lanczos_traits<result_type>::evaluation_type evaluation_type;
- return tools::checked_narrowing_cast<result_type>(detail::gamma_p_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(x), evaluation_type()), BOOST_CURRENT_FUNCTION);
+ return gamma_p_derivative(a, x, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/hermite.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/hermite.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/hermite.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/tools/config.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 namespace boost{
 namespace math{
@@ -47,13 +47,20 @@
 
 } // namespace detail
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ hermite(unsigned n, T x, const Policy&)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)");
+}
+
 template <class T>
 inline typename tools::promote_args<T>::type
    hermite(unsigned n, T x)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::hermite_imp(n, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ return boost::math::hermite(n, x, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/hypot.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/hypot.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/hypot.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,6 +8,7 @@
 
 #include <boost/math/tools/config.hpp>
 #include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <cmath>
 #include <algorithm> // for swap
@@ -18,8 +19,8 @@
 
 namespace boost{ namespace math{ namespace detail{
 
-template <class T>
-T hypot_imp(T x, T y)
+template <class T, class Policy>
+T hypot_imp(T x, T y, const Policy& pol)
 {
    //
    // Normalize x and y, so that both are positive and x >= y:
@@ -37,7 +38,7 @@
    if(std::numeric_limits<T>::has_infinity
       && ((x == std::numeric_limits<T>::infinity())
       || (y == std::numeric_limits<T>::infinity())))
- return std::numeric_limits<T>::infinity();
+ return policy::raise_overflow_error<T>("boost::math::hypot<%1%>(%1%,%1%)", 0, pol);
 #ifdef BOOST_MSVC
 #pragma warning(pop)
 #endif
@@ -60,7 +61,16 @@
 {
    typedef typename tools::promote_args<T1, T2>::type result_type;
    return detail::hypot_imp(
- static_cast<result_type>(x), static_cast<result_type>(y));
+ static_cast<result_type>(x), static_cast<result_type>(y), policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ hypot(T1 x, T2 y, const Policy& pol)
+{
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ return detail::hypot_imp(
+ static_cast<result_type>(x), static_cast<result_type>(y), pol);
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/laguerre.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/laguerre.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/laguerre.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,7 +9,7 @@
 
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <boost/math/tools/config.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 namespace boost{
 namespace math{
@@ -46,15 +46,29 @@
    return p1;
 }
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+laguerre(unsigned n, T x, const Policy&, const mpl::true_&)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, static_cast<value_type>(x)), "boost::math::laguerre<%1%>(unsigned, %1%)");
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type
+ laguerre(unsigned n, unsigned m, T x, const mpl::false_&)
+{
+ return boost::math::laguerre(n, m, x, policy::policy<>());
+}
+
 } // namespace detail
 
 template <class T>
 inline typename tools::promote_args<T>::type
    laguerre(unsigned n, T x)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::laguerre_imp(n, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ return laguerre(n, x, policy::policy<>());
 }
 
 // Recurrence for associated polynomials:
@@ -68,12 +82,12 @@
 
 namespace detail{
 // Laguerre Associated Polynomial:
-template <class T>
-T laguerre_imp(unsigned n, unsigned m, T x)
+template <class T, class Policy>
+T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol)
 {
    // Special cases:
    if(m == 0)
- return laguerre(n, x);
+ return boost::math::laguerre(n, x, pol);
 
    T p0 = 1;
    
@@ -95,13 +109,21 @@
 
 }
 
-template <class T>
+template <class T, class Policy>
 inline typename tools::promote_args<T>::type
- laguerre(unsigned n, unsigned m, T x)
+ laguerre(unsigned n, unsigned m, T x, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::laguerre_imp(n, m, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, m, static_cast<value_type>(x), pol), "boost::math::laguerre<%1%>(unsigned, unsigned, %1%)");
+}
+
+template <class T1, class T2>
+inline typename laguerre_result<T1, T2>::type
+ laguerre(unsigned n, T1 m, T2 x)
+{
+ typedef typename policy::is_policy<T2>::type tag_type;
+ return detail::laguerre(n, m, x, tag_type());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/lanczos.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/lanczos.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/lanczos.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,8 +10,9 @@
 #include <boost/mpl/if.hpp>
 #include <boost/limits.hpp>
 #include <boost/cstdint.hpp>
-#include <boost/math/tools/evaluation_type.hpp>
 #include <boost/math/tools/rational.hpp>
+#include <boost/math/policy/policy.hpp>
+#include <boost/mpl/less_equal.hpp>
 
 #include <limits.h>
 
@@ -32,8 +33,12 @@
 // Max experimental error (with arbitary precision arithmetic) 9.516e-12
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos6
+struct lanczos6 : public mpl::int_<35>
 {
+ //
+ // Produces slightly better than float precision when evaluated at
+ // double precision:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -124,8 +129,12 @@
 // Max experimental error (with arbitary precision arithmetic) 2.16676e-19
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos11
+struct lanczos11 : public mpl::int_<60>
 {
+ //
+ // Produces slightly better than double precision when evaluated at
+ // extended-double precision:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -246,8 +255,12 @@
 // Max experimental error (with arbitary precision arithmetic) 9.2213e-23
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos13
+struct lanczos13 : public mpl::int_<72>
 {
+ //
+ // Produces slightly better than extended-double precision when evaluated at
+ // higher precision:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -380,8 +393,12 @@
 // Max experimental error (with arbitary precision arithmetic) 2.9524e-38
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos22
+struct lanczos22 : public mpl::int_<120>
 {
+ //
+ // Produces slightly better than 128-bit long-double precision when
+ // evaluated at higher precision:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -568,8 +585,11 @@
 // Max experimental error (with arbitary precision arithmetic) 8.111667e-8
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos6m24
+struct lanczos6m24 : public mpl::int_<24>
 {
+ //
+ // Use for float precision, when evaluated as a float:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -660,8 +680,11 @@
 // Max experimental error (with arbitary precision arithmetic) 1.196214e-17
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos13m53
+struct lanczos13m53 : public mpl::int_<53>
 {
+ //
+ // Use for double precision, when evaluated as a double:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -794,8 +817,11 @@
 // Max experimental error (with arbitary precision arithmetic) 2.7699e-26
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos17m64
+struct lanczos17m64 : public mpl::int_<64>
 {
+ //
+ // Use for extended-double precision, when evaluated as an extended-double:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -952,8 +978,11 @@
 // Max experimental error (with arbitary precision arithmetic) 1.0541e-38
 // Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
 //
-struct lanczos24m113
+struct lanczos24m113 : public mpl::int_<113>
 {
+ //
+ // Use for long-double precision, when evaluated as an long-double:
+ //
    template <class T>
    static T lanczos_sum(const T& z)
    {
@@ -1151,109 +1180,45 @@
 //
 // placeholder for no lanczos info available:
 //
-struct undefined_lanczos
-{
-};
-
-//
-// lanczos_traits, specialise this to point tgamma etc to
-// the necessary data for type T:
-//
-template <class T>
-struct lanczos_traits
-{
- typedef T value_type;
- // typedef undefined_lanczos evaluation_type;
- typedef typename mpl::if_c<
- (std::numeric_limits<T>::is_specialized == 0)
- || (std::numeric_limits<T>::digits > 113),
- undefined_lanczos,
- typename mpl::if_c<
- std::numeric_limits<T>::digits <= 24,
- lanczos6m24,
- typename mpl::if_c<
- std::numeric_limits<T>::digits <= 53,
- lanczos13m53,
- typename mpl::if_c<
- std::numeric_limits<T>::digits <= 64,
- lanczos17m64,
- lanczos24m113
- >::type
- >::type
- >::type
- >::type evaluation_type;
-};
+struct undefined_lanczos : public mpl::int_<INT_MAX - 1> { };
 
+#if 0
 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
-#define BOOST_MATH_FLT_DIGITS std::numeric_limits<float>::digits
-#define BOOST_MATH_DBL_DIGITS std::numeric_limits<double>::digits
-#define BOOST_MATH_LDBL_DIGITS std::numeric_limits<long double>::digits
+#define BOOST_MATH_FLT_DIGITS ::std::numeric_limits<float>::digits
+#define BOOST_MATH_DBL_DIGITS ::std::numeric_limits<double>::digits
+#define BOOST_MATH_LDBL_DIGITS ::std::numeric_limits<long double>::digits
 #else
 #define BOOST_MATH_FLT_DIGITS FLT_MANT_DIG
 #define BOOST_MATH_DBL_DIGITS DBL_MANT_DIG
 #define BOOST_MATH_LDBL_DIGITS LDBL_MANT_DIG
 #endif
-
-template<>
-struct lanczos_traits<float>
-{
- typedef boost::math::tools::evaluation<float>::type value_type;
- typedef boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 40,
- lanczos6, lanczos6m24>::type evaluation_type;
-};
-
-template<>
-struct lanczos_traits<double>
-{
- typedef boost::math::tools::evaluation<double>::type value_type;
-#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- typedef boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 100,
- lanczos13,
- boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 64,
- lanczos17m64,
- boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 53,
- lanczos13m53,
- lanczos6m24>::type
- >::type
- >::type evaluation_type;
-#else
- typedef boost::mpl::if_c<
- BOOST_MATH_LDBL_DIGITS >= 100,
- lanczos13,
- boost::mpl::if_c<
- BOOST_MATH_LDBL_DIGITS >= 64,
- lanczos17m64,
- boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 53,
- lanczos13m53,
- lanczos6m24>::type
- >::type
- >::type evaluation_type;
 #endif
-};
 
-template<>
-struct lanczos_traits<long double>
+typedef mpl::list<
+ lanczos6m24,
+/* lanczos6, */
+ lanczos13m53,
+/* lanczos13, */
+ lanczos17m64,
+ lanczos24m113,
+ lanczos22,
+ undefined_lanczos> lanczos_list;
+
+template <class Real, class Policy>
+struct lanczos
 {
- typedef long double value_type;
- typedef
- boost::mpl::if_c<
- (BOOST_MATH_LDBL_DIGITS < 52),
- lanczos6m24,
- boost::mpl::if_c<
- (BOOST_MATH_LDBL_DIGITS < 55),
- lanczos13m53,
- boost::mpl::if_c<
- (BOOST_MATH_LDBL_DIGITS < 65),
- lanczos17m64,
- lanczos24m113
- >::type
- >::type
- >::type evaluation_type;
+ typedef typename mpl::if_<
+ typename mpl::less_equal<
+ typename policy::precision<Real, Policy>::type,
+ mpl::int_<0>
+ >::type,
+ mpl::int_<INT_MAX - 2>,
+ typename policy::precision<Real, Policy>::type
+ >::type target_precision;
+
+ typedef typename mpl::deref<typename mpl::find_if<
+ lanczos_list,
+ mpl::less_equal<target_precision, mpl::_1> >::type>::type type;
 };
 
 } // namespace lanczos

Modified: sandbox/math_toolkit/boost/math/special_functions/legendre.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/legendre.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/legendre.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -26,21 +26,22 @@
 namespace detail{
 
 // Implement Legendre P and Q polynomials via recurrance:
-template <class T>
-T legendre_imp(unsigned l, T x, bool second = false)
+template <class T, class Policy>
+T legendre_imp(unsigned l, T x, const Policy& pol, bool second = false)
 {
+ static const char* function = "boost::math::legrendre_p<%1%>(unsigned, %1%)";
    // Error handling:
    if((x < -1) || (x > 1))
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(
+ function,
          "The Legendre Polynomial is defined for"
- " -1 <= x <= 1, but got x = %1%.", x);
+ " -1 <= x <= 1, but got x = %1%.", x, pol);
 
    T p0, p1;
    if(second)
    {
       // A solution of the second kind (Q):
- p0 = (boost::math::log1p(x) - boost::math::log1p(-x)) / 2;
+ p0 = (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
       p1 = x * p0 - 1;
    }
    else
@@ -65,24 +66,39 @@
 
 } // namespace detail
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ legendre_p(int l, T x, const Policy& pol)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ static const char* function = "boost::math::legendre_p<%1%>(unsigned, %1%)";
+ if(l < 0)
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(-l-1, static_cast<value_type>(x), pol, false), function);
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(l, static_cast<value_type>(x), pol, false), function);
+}
+
 template <class T>
 inline typename tools::promote_args<T>::type
    legendre_p(int l, T x)
 {
+ return boost::math::legendre_p(l, x, policy::policy<>());
+}
+
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ legendre_q(unsigned l, T x, const Policy& pol)
+{
    typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- if(l < 0)
- return tools::checked_narrowing_cast<result_type>(detail::legendre_imp(-l-1, static_cast<value_type>(x), false), BOOST_CURRENT_FUNCTION);
- return tools::checked_narrowing_cast<result_type>(detail::legendre_imp(l, static_cast<value_type>(x), false), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(l, static_cast<value_type>(x), pol, true), "boost::math::legendre_q<%1%>(unsigned, %1%)");
 }
 
 template <class T>
 inline typename tools::promote_args<T>::type
    legendre_q(unsigned l, T x)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::legendre_imp(l, static_cast<value_type>(x), true), BOOST_CURRENT_FUNCTION);
+ return boost::math::legendre_q(l, x, policy::policy<>());
 }
 
 // Recurrence for associated polynomials:
@@ -96,30 +112,30 @@
 
 namespace detail{
 // Legendre P associated polynomial:
-template <class T>
-T legendre_p_imp(int l, int m, T x, T sin_theta_power)
+template <class T, class Policy>
+T legendre_p_imp(int l, int m, T x, T sin_theta_power, const Policy& pol)
 {
    // Error handling:
    if((x < -1) || (x > 1))
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION,
+ return policy::raise_domain_error<T>(
+ "boost::math::legendre_p<%1%>(int, int, %1%)",
          "The associated Legendre Polynomial is defined for"
- " -1 <= x <= 1, but got x = %1%.", x);
+ " -1 <= x <= 1, but got x = %1%.", x, pol);
    // Handle negative arguments first:
    if(l < 0)
- return legendre_p_imp(-l-1, m, x, sin_theta_power);
+ return legendre_p_imp(-l-1, m, x, sin_theta_power, pol);
    if(m < 0)
    {
       int sign = (m&1) ? -1 : 1;
- return sign * tgamma_ratio(static_cast<T>(l+m+1), static_cast<T>(l+1-m)) * legendre_p_imp(l, -m, x, sin_theta_power);
+ return sign * tgamma_ratio(static_cast<T>(l+m+1), static_cast<T>(l+1-m), pol) * legendre_p_imp(l, -m, x, sin_theta_power, pol);
    }
    // Special cases:
    if(m > l)
       return 0;
    if(m == 0)
- return legendre_p(l, x);
+ return legendre_p(l, x, pol);
 
- T p0 = boost::math::double_factorial<T>(2 * m - 1) * sin_theta_power;
+ T p0 = boost::math::double_factorial<T>(2 * m - 1, pol) * sin_theta_power;
    
    if(m&1)
       p0 *= -1;
@@ -139,23 +155,30 @@
    return p1;
 }
 
-template <class T>
-inline T legendre_p_imp(int l, int m, T x)
+template <class T, class Policy>
+inline T legendre_p_imp(int l, int m, T x, const Policy& pol)
 {
    using namespace std;
    // TODO: we really could use that mythical "pow1p" function here:
- return legendre_p_imp(l, m, x, pow(1 - x*x, T(abs(m))/2));
+ return legendre_p_imp(l, m, x, pow(1 - x*x, T(abs(m))/2), pol);
+}
+
 }
 
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ legendre_p(int l, int m, T x, const Policy& pol)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::legendre_p_imp(l, m, static_cast<value_type>(x), pol), "bost::math::legendre_p<%1%>(int, int, %1%)");
 }
 
 template <class T>
 inline typename tools::promote_args<T>::type
    legendre_p(int l, int m, T x)
 {
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::legendre_p_imp(l, m, static_cast<value_type>(x)), BOOST_CURRENT_FUNCTION);
+ return boost::math::legendre_p(l, m, x, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,7 +11,7 @@
 #include <boost/limits.hpp>
 #include <boost/math/tools/config.hpp>
 #include <boost/math/tools/series.hpp>
-#include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 
 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
@@ -63,23 +63,25 @@
 // require up to std::numeric_limits<T>::digits+1 terms to be calculated.
 // It would be much more efficient to use the equivalence:
 // log(1+x) == (log(1+x) * x) / ((1-x) - 1)
-// Unfortunately optimizing compilers make such a mess of this, that it performs
-// no better than log(1+x): which is to say not very well at all.
+// Unfortunately many optimizing compilers make such a mess of this, that
+// it performs no better than log(1+x): which is to say not very well at all.
 //
-template <class T>
-typename tools::promote_args<T>::type log1p(T x)
+template <class T, class Policy>
+typename tools::promote_args<T>::type log1p(T x, const Policy& pol)
 { // The function returns the natural logarithm of 1 + x.
   // A domain error occurs if x < -1. TODO should there be a check?
    typedef typename tools::promote_args<T>::type result_type;
    using namespace std;
    using std::abs;
 
+ static const char* function = "boost::math::log1p<%1%>(%1%)";
+
    if(x < -1)
- return tools::domain_error<T>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<T>(
+ function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<T>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<T>(
+ function, 0, pol);
 
    result_type a = abs(result_type(x));
    if(a > result_type(0.5L))
@@ -91,12 +93,12 @@
    detail::log1p_series<result_type> s(x);
    boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- result_type result = tools::sum_series(s, tools::digits<T>() + 2, max_iter);
+ result_type result = tools::sum_series(s, policy::digits<result_type, Policy>(), max_iter);
 #else
    result_type zero = 0;
- result_type result = tools::sum_series(s, tools::digits<T>() + 2, max_iter, zero);
+ result_type result = tools::sum_series(s, policy::digits<result_type, Policy>(), max_iter, zero);
 #endif
- tools::check_series_iterations(BOOST_CURRENT_FUNCTION, max_iter);
+ policy::check_series_iterations(function, max_iter, pol);
    return result;
 }
 
@@ -127,50 +129,50 @@
 # if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) \
    || defined(linux) || defined(__linux) || defined(__linux__) \
    || defined(__hpux)
-template <>
-inline float log1p<float>(float x)
+template <class Policy>
+inline float log1p(float x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<float>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<float>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<float>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<float>(
+ "log1p<%1%>(%1%)", 0, pol);
    return ::log1pf(x);
 }
-template <>
-inline long double log1p<long double>(long double x)
+template <class Policy>
+inline long double log1p(long double x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<long double>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<long double>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<long double>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<long double>(
+ "log1p<%1%>(%1%)", 0, pol);
    return ::log1pl(x);
 }
 #else
-template <>
-inline float log1p<float>(float x)
+template <class Policy>
+inline float log1p(float x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<float>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<float>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<float>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<float>(
+ "log1p<%1%>(%1%)", 0, pol);
    return ::log1p(x);
 }
 #endif
-template <>
-inline double log1p<double>(double x)
+template <class Policy>
+inline double log1p(double x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<double>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<double>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<double>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<double>(
+ "log1p<%1%>(%1%)", 0, pol);
    return ::log1p(x);
 }
 #elif defined(_MSC_VER) && (BOOST_MSVC >= 1400)
@@ -179,35 +181,35 @@
 // that your compilers optimizer won't mess this code up!!
 // Currently tested with VC8 and Intel 9.1.
 //
-template <>
-inline double log1p<double>(double x)
+template <class Policy>
+inline double log1p(double x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<double>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<double>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<double>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<double>(
+ "log1p<%1%>(%1%)", 0, pol);
    double u = 1+x;
    if(u == 1.0)
       return x;
    else
       return log(u)*(x/(u-1.0));
 }
-template <>
-inline float log1p<float>(float x)
+template <class Policy>
+inline float log1p(float x, const Policy& pol)
 {
- return static_cast<float>(boost::math::log1p<double>(x));
+ return static_cast<float>(boost::math::log1p(static_cast<double>(x), pol));
 }
-template <>
-inline long double log1p<long double>(long double x)
+template <class Policy>
+inline long double log1p(long double x, const Policy& pol)
 {
    if(x < -1)
- return tools::domain_error<long double>(
- BOOST_CURRENT_FUNCTION, "log1p(x) requires x > -1, but got x = %1%.", x);
+ return policy::raise_domain_error<long double>(
+ "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
    if(x == -1)
- return -tools::overflow_error<long double>(
- BOOST_CURRENT_FUNCTION);
+ return -policy::raise_overflow_error<long double>(
+ "log1p<%1%>(%1%)", 0, pol);
    long double u = 1+x;
    if(u == 1.0)
       return x;
@@ -216,6 +218,55 @@
 }
 #endif
 
+template <class T>
+inline typename tools::promote_args<T>::type log1p(T x)
+{
+ return boost::math::log1p(x, policy::policy<>());
+}
+//
+// Compute log(1+x)-x:
+//
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type
+ log1pmx(T x, const Policy& pol)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ using namespace std;
+ static const char* function = "boost::math::log1pmx<%1%>(%1%)";
+
+ if(x < -1)
+ return policy::raise_domain_error<T>(
+ function, "log1pmx(x) requires x > -1, but got x = %1%.", x, pol);
+ if(x == -1)
+ return -policy::raise_overflow_error<T>(
+ function, 0, pol);
+
+ result_type a = abs(result_type(x));
+ if(a > result_type(0.95L))
+ return log(1 + result_type(x)) - result_type(x);
+ // Note that without numeric_limits specialisation support,
+ // epsilon just returns zero, and our "optimisation" will always fail:
+ if(a < tools::epsilon<result_type>())
+ return -x * x / 2;
+ boost::math::detail::log1p_series<T> s(x);
+ s();
+ boost::uintmax_t max_iter = BOOST_MATH_MAX_ITER;
+#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
+ T zero = 0;
+ T result = boost::math::tools::sum_series(s, policy::digits<T, Policy>(), max_iter, zero);
+#else
+ T result = boost::math::tools::sum_series(s, policy::digits<T, Policy>(), max_iter);
+#endif
+ policy::check_series_iterations(function, max_iter, pol);
+ return result;
+}
+
+template <class T>
+inline T log1pmx(T x)
+{
+ return log1pmx(x, policy::policy<>());
+}
+
 } // namespace math
 } // namespace boost
 

Modified: sandbox/math_toolkit/boost/math/special_functions/math_fwd.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/math_fwd.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/math_fwd.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -20,8 +20,12 @@
 #define BOOST_MATH_SPECIAL_MATH_FWD_HPP
 
 #include <boost/math/tools/promotion.hpp> // for argument promotion.
+#include <boost/math/policy/policy.hpp>
+#include <boost/mpl/comparison.hpp>
 #include <complex>
 
+#define BOOST_NO_MACRO_EXPAND /**/
+
 namespace boost
 {
         namespace math
@@ -32,54 +36,130 @@
    typename tools::promote_args<RT1, RT2>::type
          beta(RT1 a, RT2 b); // Beta function (2 arguments).
 
- template <class RT1, class RT2, class RT3>
+ template <class RT1, class RT2, class A>
+ typename tools::promote_args<RT1, RT2, A>::type
+ beta(RT1 a, RT2 b, A x); // Beta function (3 arguments).
+
+ template <class RT1, class RT2, class RT3, class Policy>
    typename tools::promote_args<RT1, RT2, RT3>::type
- beta(RT1 a, RT2 b, RT3 x); // Beta function (3 arguments).
+ beta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Beta function (3 arguments).
 
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          betac(RT1 a, RT2 b, RT3 x);
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ betac(RT1 a, RT2 b, RT3 x, const Policy& pol);
+
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          ibeta(RT1 a, RT2 b, RT3 x); // Incomplete beta function.
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta function.
+
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          ibetac(RT1 a, RT2 b, RT3 x); // Incomplete beta complement function.
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta complement function.
+
    template <class T1, class T2, class T3, class T4>
    typename tools::promote_args<T1, T2, T3, T4>::type
          ibeta_inv(T1 a, T2 b, T3 p, T4* py);
 
+ template <class T1, class T2, class T3, class T4, class Policy>
+ typename tools::promote_args<T1, T2, T3, T4>::type
+ ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy& pol);
+
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          ibeta_inv(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function.
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_inv(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function.
+
+ template <class RT1, class RT2, class RT3>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_inva(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function.
+
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_inva(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function.
+
+ template <class RT1, class RT2, class RT3>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_invb(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function.
+
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_invb(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function.
+
    template <class T1, class T2, class T3, class T4>
    typename tools::promote_args<T1, T2, T3, T4>::type
          ibetac_inv(T1 a, T2 b, T3 q, T4* py);
 
+ template <class T1, class T2, class T3, class T4, class Policy>
+ typename tools::promote_args<T1, T2, T3, T4>::type
+ ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy& pol);
+
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          ibetac_inv(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function.
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_inv(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function.
+
+ template <class RT1, class RT2, class RT3>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_inva(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function.
+
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_inva(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function.
+
+ template <class RT1, class RT2, class RT3>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_invb(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function.
+
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibetac_invb(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function.
+
    template <class RT1, class RT2, class RT3>
    typename tools::promote_args<RT1, RT2, RT3>::type
          ibeta_derivative(RT1 a, RT2 b, RT3 x); // derivative of incomplete beta
 
+ template <class RT1, class RT2, class RT3, class Policy>
+ typename tools::promote_args<RT1, RT2, RT3>::type
+ ibeta_derivative(RT1 a, RT2 b, RT3 x, const Policy& pol); // derivative of incomplete beta
+
    // erf & erfc error functions.
    template <class RT> // Error function.
    typename tools::promote_args<RT>::type erf(RT z);
+ template <class RT, class Policy> // Error function.
+ typename tools::promote_args<RT>::type erf(RT z, const Policy&);
 
    template <class RT>// Error function complement.
    typename tools::promote_args<RT>::type erfc(RT z);
+ template <class RT, class Policy>// Error function complement.
+ typename tools::promote_args<RT>::type erfc(RT z, const Policy&);
 
    template <class RT>// Error function inverse.
    typename tools::promote_args<RT>::type erf_inv(RT z);
+ template <class RT, class Policy>// Error function inverse.
+ typename tools::promote_args<RT>::type erf_inv(RT z, const Policy& pol);
 
    template <class RT>// Error function complement inverse.
    typename tools::promote_args<RT>::type erfc_inv(RT z);
+ template <class RT, class Policy>// Error function complement inverse.
+ typename tools::promote_args<RT>::type erfc_inv(RT z, const Policy& pol);
 
    // Polynomials:
    template <class T1, class T2, class T3>
@@ -90,10 +170,18 @@
    typename tools::promote_args<T>::type
          legendre_p(int l, T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type
+ legendre_p(int l, T x, const Policy& pol);
+
    template <class T>
    typename tools::promote_args<T>::type
          legendre_q(unsigned l, T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type
+ legendre_q(unsigned l, T x, const Policy& pol);
+
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type
          legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1);
@@ -102,6 +190,10 @@
    typename tools::promote_args<T>::type
          legendre_p(int l, int m, T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type
+ legendre_p(int l, int m, T x, const Policy& pol);
+
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type
          laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1);
@@ -112,8 +204,34 @@
 
    template <class T>
    typename tools::promote_args<T>::type
+ laguerre(unsigned n, T x);
+
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type
+ laguerre(unsigned n, unsigned m, T x, const Policy& pol);
+
+ template <class T1, class T2>
+ struct laguerre_result
+ {
+ typedef typename mpl::if_<
+ policy::is_policy<T2>,
+ typename tools::promote_args<T1>::type,
+ typename tools::promote_args<T2>::type
+ >::type type;
+ };
+
+ template <class T1, class T2>
+ typename laguerre_result<T1, T2>::type
+ laguerre(unsigned n, T1 m, T2 x);
+
+ template <class T>
+ typename tools::promote_args<T>::type
       hermite(unsigned n, T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type
+ hermite(unsigned n, T x, const Policy& pol);
+
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type
       hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1);
@@ -122,46 +240,83 @@
    std::complex<typename tools::promote_args<T1, T2>::type>
          spherical_harmonic(unsigned n, int m, T1 theta, T2 phi);
 
+ template <class T1, class T2, class Policy>
+ std::complex<typename tools::promote_args<T1, T2>::type>
+ spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type
          spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type
+ spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type
          spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type
+ spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);
+
    // Elliptic integrals:
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type
          ellint_rf(T1 x, T2 y, T3 z);
 
+ template <class T1, class T2, class T3, class Policy>
+ typename tools::promote_args<T1, T2, T3>::type
+ ellint_rf(T1 x, T2 y, T3 z, const Policy& pol);
+
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type
          ellint_rd(T1 x, T2 y, T3 z);
 
+ template <class T1, class T2, class T3, class Policy>
+ typename tools::promote_args<T1, T2, T3>::type
+ ellint_rd(T1 x, T2 y, T3 z, const Policy& pol);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type
          ellint_rc(T1 x, T2 y);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type
+ ellint_rc(T1 x, T2 y, const Policy& pol);
+
    template <class T1, class T2, class T3, class T4>
    typename tools::promote_args<T1, T2, T3, T4>::type
          ellint_rj(T1 x, T2 y, T3 z, T4 p);
 
+ template <class T1, class T2, class T3, class T4, class Policy>
+ typename tools::promote_args<T1, T2, T3, T4>::type
+ ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol);
+
    template <typename T>
    typename tools::promote_args<T>::type ellint_2(T k);
 
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol);
+
    template <typename T>
    typename tools::promote_args<T>::type ellint_1(T k);
 
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol);
+
    template <class T1, class T2, class T3>
    typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi);
 
+ template <class T1, class T2, class T3, class Policy>
+ typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v);
 
@@ -171,17 +326,26 @@
    struct max_factorial;
    template <class RT>
    RT factorial(unsigned int);
+ template <class RT, class Policy>
+ RT factorial(unsigned int, const Policy& pol);
    template <class RT>
    RT unchecked_factorial(unsigned int);
    template <class RT>
    RT double_factorial(unsigned i);
+ template <class RT, class Policy>
+ RT double_factorial(unsigned i, const Policy& pol);
 
    template <class RT>
    typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n, const Policy& pol);
+
    template <class RT>
    typename tools::promote_args<RT>::type rising_factorial(RT x, unsigned n);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type rising_factorial(RT x, unsigned n, const Policy& pol);
 
    // Fpclassify - classify floating-point as NaN or infinity...
    template <class T>
@@ -194,88 +358,559 @@
    template <class RT>
    typename tools::promote_args<RT>::type tgamma1pm1(RT z);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type tgamma1pm1(RT z, const Policy& pol);
+
    template <class RT1, class RT2>
    typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z);
 
+ template <class RT1, class RT2, class Policy>
+ typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z, const Policy& pol);
+
    template <class RT>
    typename tools::promote_args<RT>::type lgamma(RT z, int* sign);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type lgamma(RT z, int* sign, const Policy& pol);
+
    template <class RT>
    typename tools::promote_args<RT>::type lgamma(RT x);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type lgamma(RT x, const Policy& pol);
+
    template <class RT1, class RT2>
    typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z);
 
+ template <class RT1, class RT2, class Policy>
+ typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z, const Policy&);
+
    template <class RT1, class RT2>
    typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z);
 
+ template <class RT1, class RT2, class Policy>
+ typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z, const Policy&);
+
    template <class RT1, class RT2>
    typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z);
 
+ template <class RT1, class RT2, class Policy>
+ typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z, const Policy&);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta, const Policy&);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b, const Policy&);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x, const Policy&);
+
    // gamma inverse.
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p, const Policy&);
+
+ template <class T1, class T2>
+ typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p);
+
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p, const Policy&);
+
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q, const Policy&);
+
+ template <class T1, class T2>
+ typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q);
+
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q, const Policy&);
+
    // digamma:
    template <class T>
    typename tools::promote_args<T>::type digamma(T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type digamma(T x, const Policy&);
+
    // Hypotenuse function sqrt(x ^ 2 + y ^ 2).
    template <class T1, class T2>
    typename tools::promote_args<T1, T2>::type
          hypot(T1 x, T2 y);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type
+ hypot(T1 x, T2 y, const Policy&);
+
    // cbrt - cube root.
    template <class RT>
    typename tools::promote_args<RT>::type cbrt(RT z);
 
+ template <class RT, class Policy>
+ typename tools::promote_args<RT>::type cbrt(RT z, const Policy&);
+
    // log1p is log(x + 1)
    template <class T>
    typename tools::promote_args<T>::type log1p(T);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type log1p(T, const Policy&);
+
+ // log1pmx is log(x + 1) - x
+ template <class T>
+ typename tools::promote_args<T>::type log1pmx(T);
+
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type log1pmx(T, const Policy&);
+
    // Exp (x) minus 1 functions.
    template <class T>
    typename tools::promote_args<T>::type expm1(T);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type expm1(T, const Policy&);
+
    // Power - 1
    template <class T1, class T2>
- inline typename tools::promote_args<T1, T2>::type
+ typename tools::promote_args<T1, T2>::type
          powm1(const T1 a, const T2 z);
 
+ template <class T1, class T2, class Policy>
+ typename tools::promote_args<T1, T2>::type
+ powm1(const T1 a, const T2 z, const Policy&);
+
    // sqrt(1+x) - 1
    template <class T>
    typename tools::promote_args<T>::type sqrt1pm1(const T& val);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy&);
+
    // sinus cardinals:
    template <class T>
    typename tools::promote_args<T>::type sinc_pi(T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type sinc_pi(T x, const Policy&);
+
    template <class T>
    typename tools::promote_args<T>::type sinhc_pi(T x);
 
+ template <class T, class Policy>
+ typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&);
+
    // inverse hyperbolics:
    template<typename T>
    typename tools::promote_args<T>::type asinh(const T x);
 
+ template<typename T, class Policy>
+ typename tools::promote_args<T>::type asinh(const T x, const Policy&);
+
    template<typename T>
    typename tools::promote_args<T>::type acosh(const T x);
 
+ template<typename T, class Policy>
+ typename tools::promote_args<T>::type acosh(const T x, const Policy&);
+
    template<typename T>
    typename tools::promote_args<T>::type atanh(const T x);
 
+ template<typename T, class Policy>
+ typename tools::promote_args<T>::type atanh(const T x, const Policy&);
+
+ namespace detail{
+
+ typedef mpl::int_<0> bessel_no_int_tag; // No integer optimisation possible.
+ typedef mpl::int_<1> bessel_maybe_int_tag; // Maybe integer optimisation.
+ typedef mpl::int_<2> bessel_int_tag; // Definite integer optimistaion.
+
+ template <class T1, class T2, class Policy>
+ struct bessel_traits
+ {
+ typedef typename tools::promote_args<
+ T1, T2
+ >::type result_type;
+
+ typedef typename policy::precision<result_type, Policy>::type precision_type;
+
+ typedef typename mpl::if_<
+ mpl::or_<
+ mpl::less_equal<precision_type, mpl::int_<0> >,
+ mpl::greater<precision_type, mpl::int_<64> > >,
+ bessel_no_int_tag,
+ typename mpl::if_<
+ is_integral<T1>,
+ bessel_int_tag,
+ bessel_maybe_int_tag
+ >::type
+ >::type optimisation_tag;
+ };
+ } // detail
+
+ // Bessel functions:
+ template <class T1, class T2, class Policy>
+ typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol);
+
+ template <class T1, class T2>
+ typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_j(T1 v, T2 x);
+
+ template <class T, class Policy>
+ typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& pol);
+
+ template <class T>
+ typename detail::bessel_traits<T, T, policy::policy<> >::result_type sph_bessel(unsigned v, T x);
+
+ template <class T1, class T2, class Policy>
+ typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol);
+
+ template <class T1, class T2>
+ typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_i(T1 v, T2 x);
+
+ template <class T1, class T2, class Policy>
+ typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol);
+
+ template <class T1, class T2>
+ typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_bessel_k(T1 v, T2 x);
+
+ template <class T1, class T2, class Policy>
+ typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& pol);
+
+ template <class T1, class T2>
+ typename detail::bessel_traits<T1, T2, policy::policy<> >::result_type cyl_neumann(T1 v, T2 x);
+
+ template <class T, class Policy>
+ typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& pol);
+
+ template <class T>
+ typename detail::bessel_traits<T, T, policy::policy<> >::result_type sph_neumann(unsigned v, T x);
+
+ template <class T, class Policy>
+ T sin_pi(T x, const Policy&);
+
+ template <class T>
+ T sin_pi(T x);
+
+ template <class T, class Policy>
+ T cos_pi(T x, const Policy&);
+
+ template <class T>
+ T cos_pi(T x);
+
+ template <class T>
+ int fpclassify BOOST_NO_MACRO_EXPAND(T t);
+
+ template <class T>
+ bool isfinite BOOST_NO_MACRO_EXPAND(T z);
+
+ template <class T>
+ bool isinf BOOST_NO_MACRO_EXPAND(T t);
+
+ template <class T>
+ bool isnan BOOST_NO_MACRO_EXPAND(T t);
+
+ template <class T>
+ bool isnormal BOOST_NO_MACRO_EXPAND(T t);
+
          } // namespace math
 } // namespace boost
 
+#define BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(Policy)\
+ template <class RT1, class RT2>\
+ inline typename boost::math::tools::promote_args<RT1, RT2>::type \
+ beta(RT1 a, RT2 b) { return ::boost::math::beta(a, b, Policy()); }\
+\
+ template <class RT1, class RT2, class A>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, A>::type \
+ beta(RT1 a, RT2 b, A x){ return ::boost::math::beta(a, b, x, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ betac(RT1 a, RT2 b, RT3 x) { return ::boost::math::betac(a, b, x, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibeta(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta(a, b, x, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibetac(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibetac(a, b, x, Policy()); }\
+\
+ template <class T1, class T2, class T3, class T4>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \
+ ibeta_inv(T1 a, T2 b, T3 p, T4* py){ return ::boost::math::ibeta_inv(a, b, p, py, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibeta_inv(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inv(a, b, p, Policy()); }\
+\
+ template <class T1, class T2, class T3, class T4>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \
+ ibetac_inv(T1 a, T2 b, T3 q, T4* py){ return ::boost::math::ibetac_inv(a, b, q, py, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibeta_inva(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inva(a, b, p, Policy()); }\
+\
+ template <class T1, class T2, class T3>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3>::type \
+ ibetac_inva(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_inva(a, b, q, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibeta_invb(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_invb(a, b, p, Policy()); }\
+\
+ template <class T1, class T2, class T3>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3>::type \
+ ibetac_invb(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_invb(a, b, q, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibetac_inv(RT1 a, RT2 b, RT3 q){ return ::boost::math::ibetac_inv(a, b, q, Policy()); }\
+\
+ template <class RT1, class RT2, class RT3>\
+ inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \
+ ibeta_derivative(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta_derivative(a, b, x, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type erf(RT z) { return ::boost::math::erf(z, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type erfc(RT z){ return ::boost::math::erfc(z, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type erf_inv(RT z) { return ::boost::math::erf_inv(z, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type erfc_inv(RT z){ return ::boost::math::erfc_inv(z, Policy()); }\
+\
+ using boost::math::legendre_next;\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type \
+ legendre_p(int l, T x){ return ::boost::math::legendre_p(l, x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type \
+ legendre_q(unsigned l, T x){ return ::boost::math::legendre_q(l, x, Policy()); }\
+\
+ using ::boost::math::legendre_next;\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type \
+ legendre_p(int l, int m, T x){ return ::boost::math::legendre_p(l, m, x, Policy()); }\
+\
+ using ::boost::math::laguerre_next;\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type \
+ laguerre(unsigned n, T x){ return ::boost::math::laguerre(n, x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::laguerre_result<T1, T2>::type \
+ laguerre(unsigned n, T1 m, T2 x) { return ::boost::math::laguerre(n, m, x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type \
+ hermite(unsigned n, T x){ return ::boost::math::hermite(n, x, Policy()); }\
+\
+ using boost::math::hermite_next;\
+\
+ template <class T1, class T2>\
+ inline std::complex<typename boost::math::tools::promote_args<T1, T2>::type> \
+ spherical_harmonic(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic(n, m, theta, phi, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi){ return ::boost::math::spherical_harmonic_r(n, m, theta, phi, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic_i(n, m, theta, phi, Policy()); }\
+\
+ template <class T1, class T2, class Policy>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);\
+\
+ template <class T1, class T2, class T3>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3>::type \
+ ellint_rf(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rf(x, y, z, Policy()); }\
+\
+ template <class T1, class T2, class T3>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3>::type \
+ ellint_rd(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rd(x, y, z, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ ellint_rc(T1 x, T2 y){ return ::boost::math::ellint_rc(x, y, Policy()); }\
+\
+ template <class T1, class T2, class T3, class T4>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \
+ ellint_rj(T1 x, T2 y, T3 z, T4 p){ return boost::math::ellint_rj(x, y, z, p, Policy()); }\
+\
+ template <typename T>\
+ inline typename boost::math::tools::promote_args<T>::type ellint_2(T k){ return boost::math::ellint_2(k, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi){ return boost::math::ellint_2(k, phi, Policy()); }\
+\
+ template <typename T>\
+ inline typename boost::math::tools::promote_args<T>::type ellint_1(T k){ return boost::math::ellint_1(k, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi){ return boost::math::ellint_1(k, phi, Policy()); }\
+\
+ template <class T1, class T2, class T3>\
+ inline typename boost::math::tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi){ return boost::math::ellint_3(k, v, phi, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v){ return boost::math::ellint_3(k, v, Policy()); }\
+\
+ using boost::math::max_factorial;\
+ template <class RT>\
+ inline RT factorial(unsigned int i) { return boost::math::factorial<RT>(i, Policy()); }\
+ using boost::math::unchecked_factorial;\
+ template <class RT>\
+ inline RT double_factorial(unsigned i){ return boost::math::double_factorial<RT>(i, Policy()); }\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type falling_factorial(RT x, unsigned n){ return boost::math::falling_factorial(x, n, Policy()); }\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type rising_factorial(RT x, unsigned n){ return boost::math::rising_factorial(x, n, Policy()); }\
+ using boost::math::fpclassify;\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type tgamma(RT z){ return boost::math::tgamma(z, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type tgamma1pm1(RT z){ return boost::math::tgamma1pm1(z, Policy()); }\
+\
+ template <class RT1, class RT2>\
+ inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z){ return boost::math::tgamma(a, z, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type lgamma(RT z, int* sign){ return boost::math::lgamma(z, sign, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type lgamma(RT x){ return boost::math::lgamma(x, Policy()); }\
+\
+ template <class RT1, class RT2>\
+ inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z){ return boost::math::tgamma_lower(a, z, Policy()); }\
+\
+ template <class RT1, class RT2>\
+ inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z){ return boost::math::gamma_q(a, z, Policy()); }\
+\
+ template <class RT1, class RT2>\
+ inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z){ return boost::math::gamma_p(a, z, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta){ return boost::math::tgamma_delta_ratio(z, delta, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b) { return boost::math::tgamma_ratio(a, b, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x){ return boost::math::gamma_p_derivative(a, x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p){ return boost::math::gamma_p_inv(a, p, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p){ return boost::math::gamma_p_inva(a, p, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q){ return boost::math::gamma_q_inv(a, q, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q){ return boost::math::gamma_q_inva(a, q, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type digamma(T x){ return boost::math::digamma(x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ hypot(T1 x, T2 y){ return boost::math::hypot(x, y, Policy()); }\
+\
+ template <class RT>\
+ inline typename boost::math::tools::promote_args<RT>::type cbrt(RT z){ return boost::math::cbrt(z, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type log1p(T x){ return boost::math::log1p(x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type log1pmx(T x){ return boost::math::log1pmx(x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type expm1(T x){ return boost::math::expm1(x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::tools::promote_args<T1, T2>::type \
+ powm1(const T1 a, const T2 z){ return boost::math::powm1(a, z, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type sqrt1pm1(const T& val){ return boost::math::sqrt1pm1(val, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type sinc_pi(T x){ return boost::math::sinc_pi(x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::tools::promote_args<T>::type sinhc_pi(T x){ return boost::math::sinhc_pi(x, Policy()); }\
+\
+ template<typename T>\
+ inline typename boost::math::tools::promote_args<T>::type asinh(const T x){ return boost::math::asinh(x, Policy()); }\
+\
+ template<typename T>\
+ inline typename boost::math::tools::promote_args<T>::type acosh(const T x){ return boost::math::acosh(x, Policy()); }\
+\
+ template<typename T>\
+ inline typename boost::math::tools::promote_args<T>::type atanh(const T x){ return boost::math::atanh(x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type cyl_bessel_j(T1 v, T2 x)\
+ { return boost::math::cyl_bessel_j(v, x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type sph_bessel(unsigned v, T x)\
+ { return boost::math::sph_bessel(v, x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \
+ cyl_bessel_i(T1 v, T2 x) { return boost::math::cyl_bessel_i(v, x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \
+ cyl_bessel_k(T1 v, T2 x) { return boost::math::cyl_bessel_k(v, x, Policy()); }\
+\
+ template <class T1, class T2>\
+ inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \
+ cyl_neumann(T1 v, T2 x){ return boost::math::cyl_neumann(v, x, Policy()); }\
+\
+ template <class T>\
+ inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type \
+ sph_neumann(unsigned v, T x){ return boost::math::sph_neumann(v, x, Policy()); }\
+\
+ template <class T>\
+ inline T sin_pi(T x){ return boost::math::sin_pi(x); }\
+\
+ template <class T>\
+ inline T cos_pi(T x){ return boost::math::cos_pi(x); }\
+\
+ using boost::math::fpclassify;\
+ using boost::math::isfinite;\
+ using boost::math::isinf;\
+ using boost::math::isnan;\
+ using boost::math::isnormal;
+
 #endif // BOOST_MATH_SPECIAL_MATH_FWD_HPP

Modified: sandbox/math_toolkit/boost/math/special_functions/powm1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/powm1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/powm1.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,8 +13,8 @@
 
 namespace boost{ namespace math{ namespace detail{
 
-template <class T>
-inline T powm1_imp(const T a, const T z)
+template <class T, class Policy>
+inline T powm1_imp(const T a, const T z, const Policy& pol)
 {
    using namespace std;
 
@@ -22,7 +22,7 @@
    {
       T p = log(a) * z;
       if(fabs(p) < 2)
- return boost::math::expm1(p);
+ return boost::math::expm1(p, pol);
       // otherwise fall though:
    }
    return pow(a, z) - 1;
@@ -35,7 +35,15 @@
    powm1(const T1 a, const T2 z)
 {
    typedef typename tools::promote_args<T1, T2>::type result_type;
- return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z));
+ return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ powm1(const T1 a, const T2 z, const Policy& pol)
+{
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), pol);
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/sin_pi.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/sin_pi.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/sin_pi.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -40,6 +40,12 @@
    return invert ? -rem : rem;
 }
 
+template <class T, class Policy>
+inline T sin_pi(T x, const Policy&)
+{
+ return boost::math::sin_pi(x);
+}
+
 } // namespace math
 } // namespace boost
 #endif

Modified: sandbox/math_toolkit/boost/math/special_functions/sinc.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/sinc.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/sinc.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,6 +13,7 @@
 
 #include <boost/math/tools/config.hpp>
 #include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/policy.hpp>
 #include <boost/math/special_functions/math_fwd.hpp>
 #include <cmath>
 #include <boost/limits.hpp>
@@ -98,6 +99,13 @@
           return detail::sinc_pi_imp(static_cast<result_type>(x));
        }
 
+ template <class T, class Policy>
+ inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
+ {
+ typedef typename tools::promote_args<T>::type result_type;
+ return detail::sinc_pi_imp(static_cast<result_type>(x));
+ }
+
 #ifdef BOOST_NO_TEMPLATE_TEMPLATES
 #else /* BOOST_NO_TEMPLATE_TEMPLATES */
         template<typename T, template<typename> class U>
@@ -151,6 +159,12 @@
                 return(result);
             }
         }
+
+ template<typename T, template<typename> class U, class Policy>
+ inline U<T> sinc_pi(const U<T> x, const Policy&)
+ {
+ return sinc_pi(x);
+ }
 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
     }
 }

Modified: sandbox/math_toolkit/boost/math/special_functions/sinhc.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/sinhc.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/sinhc.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -97,6 +97,11 @@
           return detail::sinhc_pi_imp(static_cast<result_type>(x));
        }
 
+ template <class T, class Policy>
+ inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&)
+ {
+ return boost::math::sinhc_pi(x);
+ }
 
 #ifdef BOOST_NO_TEMPLATE_TEMPLATES
 #else /* BOOST_NO_TEMPLATE_TEMPLATES */

Modified: sandbox/math_toolkit/boost/math/special_functions/spherical_harmonic.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/spherical_harmonic.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/spherical_harmonic.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -20,8 +20,8 @@
 // and imaginary parts. Does *not* fix up the sign of the result
 // though.
 //
-template <class T>
-inline T spherical_harmonic_prefix(unsigned n, unsigned m, T theta)
+template <class T, class Policy>
+inline T spherical_harmonic_prefix(unsigned n, unsigned m, T theta, const Policy& pol)
 {
    using namespace std;
 
@@ -31,9 +31,9 @@
    T sin_theta = sin(theta);
    T x = cos(theta);
 
- T leg = detail::legendre_p_imp(n, m, x, pow(fabs(sin_theta), T(m)));
+ T leg = detail::legendre_p_imp(n, m, x, pow(fabs(sin_theta), T(m)), pol);
    
- T prefix = tgamma_delta_ratio(static_cast<T>(n - m + 1), static_cast<T>(2 * m));
+ T prefix = tgamma_delta_ratio(static_cast<T>(n - m + 1), static_cast<T>(2 * m), pol);
    prefix *= (2 * n + 1) / (4 * constants::pi<T>());
    prefix = sqrt(prefix);
    return prefix * leg;
@@ -41,8 +41,8 @@
 //
 // Real Part:
 //
-template <class T>
-T spherical_harmonic_r(unsigned n, int m, T theta, T phi)
+template <class T, class Policy>
+T spherical_harmonic_r(unsigned n, int m, T theta, T phi, const Policy& pol)
 {
    using namespace std; // ADL of std functions
 
@@ -63,13 +63,13 @@
          sign = !sign;
    }
    // Get the value and adjust sign as required:
- T prefix = spherical_harmonic_prefix(n, m, theta);
+ T prefix = spherical_harmonic_prefix(n, m, theta, pol);
    prefix *= cos(m * phi);
    return sign ? -prefix : prefix;
 }
 
-template <class T>
-T spherical_harmonic_i(unsigned n, int m, T theta, T phi)
+template <class T, class Policy>
+T spherical_harmonic_i(unsigned n, int m, T theta, T phi, const Policy& pol)
 {
    using namespace std; // ADL of std functions
 
@@ -90,13 +90,13 @@
          sign = !sign;
    }
    // Get the value and adjust sign as required:
- T prefix = spherical_harmonic_prefix(n, m, theta);
+ T prefix = spherical_harmonic_prefix(n, m, theta, pol);
    prefix *= sin(m * phi);
    return sign ? -prefix : prefix;
 }
 
-template <class T, class U>
-std::complex<T> spherical_harmonic(unsigned n, int m, U theta, U phi)
+template <class T, class U, class Policy>
+std::complex<T> spherical_harmonic(unsigned n, int m, U theta, U phi, const Policy& pol)
 {
    using namespace std;
    //
@@ -126,7 +126,7 @@
    //
    // Calculate the value:
    //
- U prefix = spherical_harmonic_prefix(n, m, theta);
+ U prefix = spherical_harmonic_prefix(n, m, theta, pol);
    U r = prefix * cos(m * phi);
    U i = prefix * sin(m * phi);
    //
@@ -136,36 +136,58 @@
       r = -r;
    if(i_sign)
       i = -i;
- return std::complex<T>(tools::checked_narrowing_cast<T>(r, BOOST_CURRENT_FUNCTION), tools::checked_narrowing_cast<T>(i, BOOST_CURRENT_FUNCTION));
+ static const char* function = "boost::math::spherical_harmonic<%1%>(int, int, %1%, %1%)";
+ return std::complex<T>(policy::checked_narrowing_cast<T, Policy>(r, function), policy::checked_narrowing_cast<T, Policy>(i, function));
 }
 
 } // namespace detail
 
+template <class T1, class T2, class Policy>
+inline std::complex<typename tools::promote_args<T1, T2>::type>
+ spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const Policy& pol)
+{
+ typedef typename tools::promote_args<T1, T2>::type result_type;
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return detail::spherical_harmonic<result_type, value_type>(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol);
+}
+
 template <class T1, class T2>
 inline std::complex<typename tools::promote_args<T1, T2>::type>
    spherical_harmonic(unsigned n, int m, T1 theta, T2 phi)
 {
+ return boost::math::spherical_harmonic(n, m, theta, phi, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const Policy& pol)
+{
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return detail::spherical_harmonic<result_type, value_type>(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi));
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::spherical_harmonic_r(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol), "bost::math::spherical_harmonic_r<%1%>(unsigned, int, %1%, %1%)");
 }
 
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type
    spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi)
 {
+ return boost::math::spherical_harmonic_r(n, m, theta, phi, policy::policy<>());
+}
+
+template <class T1, class T2, class Policy>
+inline typename tools::promote_args<T1, T2>::type
+ spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol)
+{
    typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::spherical_harmonic_r(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi)), BOOST_CURRENT_FUNCTION);
+ typedef typename policy::evaluation<result_type, Policy>::type value_type;
+ return policy::checked_narrowing_cast<result_type, Policy>(detail::spherical_harmonic_i(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol), "boost::math::spherical_harmonic_i<%1%>(unsigned, int, %1%, %1%)");
 }
 
 template <class T1, class T2>
 inline typename tools::promote_args<T1, T2>::type
    spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi)
 {
- typedef typename tools::promote_args<T1, T2>::type result_type;
- typedef typename tools::evaluation<result_type>::type value_type;
- return tools::checked_narrowing_cast<result_type>(detail::spherical_harmonic_i(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi)), BOOST_CURRENT_FUNCTION);
+ return boost::math::spherical_harmonic_i(n, m, theta, phi, policy::policy<>());
 }
 
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/special_functions/sqrt1pm1.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/sqrt1pm1.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/sqrt1pm1.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -16,15 +16,21 @@
 
 namespace boost{ namespace math{
 
-template <class T>
-inline typename tools::promote_args<T>::type sqrt1pm1(const T& val)
+template <class T, class Policy>
+inline typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy& pol)
 {
    typedef typename tools::promote_args<T>::type result_type;
    using namespace std;
 
    if(fabs(result_type(val)) > 0.75)
       return sqrt(1 + result_type(val)) - 1;
- return boost::math::expm1(boost::math::log1p(val) / 2);
+ return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol);
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type sqrt1pm1(const T& val)
+{
+ return sqrt1pm1(val, policy::policy<>());
 }
 
 } // namespace math

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-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -1,9 +1,11 @@
 #ifndef BOOST_MATH_TOOLS_CONFIG_HPP
 #define BOOST_MATH_TOOLS_CONFIG_HPP
 
-#include <boost/math/tools/error_handling.hpp>
 #include <boost/cstdint.hpp> // for boost::uintmax_t
 #include <boost/config.hpp>
+#include <algorithm> // for min and max
+
+#include <boost/math/tools/user.hpp>
 
 #define BOOST_MATH_MAX_ITER 1000000
 
@@ -64,14 +66,6 @@
    return (std::max)((std::max)(a, b), (std::max)(c, d));
 }
 
-inline void check_series_iterations(const char* function, boost::uintmax_t max_iter)
-{
- if(max_iter >= BOOST_MATH_MAX_ITER)
- tools::logic_error<boost::uintmax_t>(
- function,
- "Series evaluation exceeded %1% iterations, giving up now.", max_iter);
-}
-
 } // namespace tools
 }} // namespace boost namespace math
 
@@ -115,3 +109,4 @@
 #endif // BOOST_MATH_TOOLS_CONFIG_HPP
 
 
+

Deleted: sandbox/math_toolkit/boost/math/tools/error_handling.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/error_handling.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,251 +0,0 @@
-// Copyright John Maddock 2006.
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_MATH_TOOLS_ERROR_HANDLING_HPP
-#define BOOST_MATH_TOOLS_ERROR_HANDLING_HPP
-
-// Boost
-#include <boost/throw_exception.hpp>
-#include <boost/limits.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/math/tools/precision.hpp>
-#ifdef BOOST_MSVC
-# pragma warning(push) // Quiet warnings in boost/format.hpp
-# pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE
-# pragma warning(disable: 4512) // assignment operator could not be generated.
-#endif
-#include <boost/format.hpp>
-#ifdef BOOST_MSVC
-# pragma warning(pop)
-#endif
-#ifdef BOOST_MSVC
-# pragma warning(push) // Quiet warnings in error_handling
-// May also need to quiet warnings within distributions like binomial, etc
-// depending on definition, or not, of macro BOOST_MATH_THROW_ON_DOMAIN_ERROR
-// that controls if error_handling throws, or not,
-// that, in turn, determines if code is reachable, or not.
-# pragma warning(disable: 4702) // unreachable code in domain_error_imp etc
-#endif
-
-// We don't use this one directly,
-// but our clients will use it for BOOST_CURRENT_FUNCTION.
-#include <boost/current_function.hpp>
-
-// std
-#include <limits> // for numeric_limits
-#include <stdexcept>
-#include <cmath>
-#include <cerrno> // for errno
-
-namespace boost{ namespace math
-{
- namespace tools
- {
- namespace detail
- {
- template <class E>
- void raise_error(const char* function, const char* message)
- {
- if(function == 0)
- function = "Unknown function";
- if(message == 0)
- message = "Cause unknown";
-
- std::string msg("Error in function ");
- msg += function;
- msg += ": ";
- msg += message;
-
- E e(msg);
- boost::throw_exception(e);
- }
-
- template <class E, class T>
- void raise_error(const char* function, const char* message, const T& val)
- {
- if(function == 0)
- function = "Unknown function";
- if(message == 0)
- message = "Cause unknown";
-
- std::string msg("Error in function ");
- msg += function;
- msg += ": ";
- msg += message;
-
- int prec = 2 + (tools::digits<T>() * 30103UL) / 100000UL;
- msg = (boost::format(msg) % boost::io::group(std::setprecision(prec), val)).str();
-
- E e(msg);
- boost::throw_exception(e);
- }
-
- #ifndef BOOST_MATH_THROW_ON_DOMAIN_ERROR
- template <class T>
- inline T domain_error_imp(const char* /*function*/, const char* /*message*/, const T&, const mpl::true_*)
- { // No throw case.
- errno = ERANGE;
- return std::numeric_limits<T>::quiet_NaN();
- }
- #endif // BOOST_MATH_THROW_ON_DOMAIN_ERROR
- template <class T>
- inline T domain_error_imp(const char* function, const char* message, const T& val, const void*)
- { // Throw case.
- errno = ERANGE;
- detail::raise_error<std::domain_error>(function, message ? message : "Domain Error on value %1%", val);
- // We don't get here: (and may get warning C4702: unreachable code)
- return 0;
- }
-
- #ifndef BOOST_MATH_THROW_ON_OVERFLOW_ERROR
- template <class T>
- inline T overflow_error_imp(const char* /*function*/, const char* /*message*/, mpl::bool_<true> const*)
- { // No throw case.
- errno = ERANGE;
- return std::numeric_limits<T>::infinity();
- }
- #endif // BOOST_MATH_THROW_ON_OVERFLOW_ERROR
- template <class T>
- inline T overflow_error_imp(const char* function, const char* message, const void*)
- { // Throw case.
- errno = ERANGE;
- detail::raise_error<std::overflow_error>(function, message ? message : "Overflow");
- // We don't get here: (and may get warning C4702: unreachable code)
- return 0;
- }
- } // namespace detail
-
-// boost::math::tools:: Error handling functions:
-// domain_error, pole_error, overflow_error, underflow_error, denorm_error, logic_error
-// & checked_narrowing_cast.
-
-// An argument is outside its allowed range:
-// so show message & return a NaN.
-template <class T>
-inline T domain_error(const char* function, const char* message, const T& val)
-{ // returns std::numeric_limits<T>::quiet_NaN(), or as near as possible.
-#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- if(std::numeric_limits<T>::has_quiet_NaN)
- return detail::domain_error_imp<T>(function, message, val, static_cast<mpl::true_*>(0));
- return detail::domain_error_imp<T>(function, message, val, static_cast<mpl::false_*>(0));
-#else
- typedef boost::mpl::bool_< ::std::numeric_limits<T>::has_quiet_NaN> tag_type;
- return detail::domain_error_imp<T>(function, message, val, static_cast<tag_type*>(0));
-#endif
-} // domain_error
-
-// Evaluation at a pole, this is currently treated the same as a domain error:
-template <class T>
-inline T pole_error(const char* function, const char* message, const T& val)
-{
- return domain_error<T>(function, message ? message : "Evaluation at pole %1%", val);
-}
-//
-// Result too large to be represented in type T:
-// so show message & return an infinity.
-template <class T>
-inline T overflow_error(const char* function, const char* message = 0)
-{ // returns std::numeric_limits<T>::infinity(), or as near as possible.
-#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- if(std::numeric_limits<T>::has_infinity)
- return detail::overflow_error_imp<T>(function, message, static_cast<mpl::true_*>(0));
- return detail::overflow_error_imp<T>(function, message, static_cast<mpl::false_*>(0));
-#else
- typedef boost::mpl::bool_< ::std::numeric_limits<T>::has_infinity> tag_type;
- return detail::overflow_error_imp<T>(function, message, static_cast<tag_type*>(0));
-#endif
-} // overflow_error
-
-// Result too small to be represented in type T,
-// called only when we know the result is not actually zero:
-// but show message & return true zero.
-template <class T>
-#ifdef BOOST_MATH_THROW_ON_UNDERFLOW_ERROR
- inline T underflow_error(const char* function, const char* message)
-#else
- inline T underflow_error(const char*, const char*) // Warning suppressed version.
-#endif
-{
- errno = ERANGE;
-#ifdef BOOST_MATH_THROW_ON_UNDERFLOW_ERROR
- detail::raise_error<std::underflow_error>(function, message ? message : "Underflow");
-#endif
- return 0;
-} // underflow_error
-
-// Result is denormalised:
-// so use domain_error to show message & return unchanged denormalised value.
-template <class T>
-#ifdef BOOST_MATH_THROW_ON_DENORM_ERROR
- inline T denorm_error(T const& t, const char* function, const char* message)
-#else
- inline T denorm_error(T const& t, const char*, const char*) // Warning suppressed version.
-#endif
-{
- // Don't set errno if denormalized.
-#ifdef BOOST_MATH_THROW_ON_DENORM_ERROR
- // We don't have a std exception type for this, but this feels about right:
- detail::raise_error<std::underflow_error>(function, message ? message : "Denormalized value");
-#endif
- return t; // Unchanged denormalised value.
-} // denorm_error
-//
-// Computed result is garbage / internal error:
-template <class T>
-inline T logic_error(const char* function, const char* message, const T& val)
-{
- errno = EDOM;
- detail::raise_error<std::logic_error>(function, message ? message : "Internal logic error, computed value was %1%", val);
- return 0; // We don't get here:
-} // logic_error
-
-namespace detail
-{
- template <class T, class U>
- inline T checked_narrowing_cast(U const& val, const char* , const boost::mpl::true_*)
- {
- return val;
- }
-
- template <class T, class U>
- inline T checked_narrowing_cast(U const& val, const char* function, const boost::mpl::false_*)
- {
- if(val > tools::max_value<T>())
- return tools::overflow_error<T>(function);
- T result = static_cast<T>(val);
- if((result == 0) && (val != 0))
- return tools::underflow_error<T>(function, 0);
- if((fabs(result) < tools::min_value<T>()) && (fabs(val) >= tools::min_value<U>()))
- return tools::denorm_error<T>(result, function, 0);
- return result;
- }
-} // namespace detail
-
-template <class T, class U>
-inline T checked_narrowing_cast(U const& val, const char* function)
-{
-#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- typedef boost::mpl::bool_<
- ::boost::is_same<T, U>::value
- || (std::numeric_limits<T>::digits >= std::numeric_limits<U>::digits
- && std::numeric_limits<T>::min_exponent <= std::numeric_limits<U>::min_exponent
- && std::numeric_limits<T>::max_exponent >= std::numeric_limits<U>::max_exponent) > select_type;
-#else
- typedef boost::mpl::bool_<
- ::boost::is_same<T, U>::value> select_type;
-#endif
- return detail::checked_narrowing_cast<T>(val, function, static_cast<const select_type*>(0));
-} // checked_narrowing_cast
-
-} // namespace tools
-} // namespace math
-} // namespace boost
-
-#ifdef BOOST_MSVC
-# pragma warning(pop)
-#endif
-
-#endif // BOOST_MATH_TOOLS_ERROR_HANDLING_HPP
-

Deleted: sandbox/math_toolkit/boost/math/tools/evaluation_type.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/evaluation_type.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,65 +0,0 @@
-// (C) Copyright John Maddock 2006.
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_MATH_TOOLS_EVALUATION_TYPE_HPP
-#define BOOST_MATH_TOOLS_EVALUATION_TYPE_HPP
-
-#include <boost/mpl/if.hpp>
-#include <limits>
-
-namespace boost{ namespace math{ namespace tools{
-
-template <class T>
-struct evaluation
-{
- typedef T type;
-};
-
-#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
-#define BOOST_MATH_FLT_DIGITS std::numeric_limits<float>::digits
-#define BOOST_MATH_DBL_DIGITS std::numeric_limits<double>::digits
-#define BOOST_MATH_LDBL_DIGITS std::numeric_limits<long double>::digits
-#else
-#define BOOST_MATH_FLT_DIGITS FLT_MANT_DIG
-#define BOOST_MATH_DBL_DIGITS DBL_MANT_DIG
-#define BOOST_MATH_LDBL_DIGITS LDBL_MANT_DIG
-#endif
-
-template<>
-struct evaluation<float>
-{
- typedef boost::mpl::if_c<
- BOOST_MATH_DBL_DIGITS >= 40,
- double, float>::type type;
-};
-
-//
-// We don't promote to long double precision if the platform
-// doesn't have long double versions of the C std lib functions.
-//
-// If we did promote in this case we could pass out-of-range values
-// to the C std lib without realising that we were doing so,
-// as numeric_limits<long double> would give us no clue that we were
-// about to go out of range for a double.
-//
-#if !defined(__CYGWIN__) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
-template<>
-struct evaluation<double>
-{
- typedef boost::mpl::if_c<
- BOOST_MATH_LDBL_DIGITS >= 64,
- long double,
- double>::type type;
-};
-#endif
-
-} // namespace tools
-} // namespace math
-} // namespace boost
-
-#endif // BOOST_MATH_TOOLS_EVALUATION_TYPE_HPP
-
-
-

Modified: sandbox/math_toolkit/boost/math/tools/minima.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/minima.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/minima.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 #include <utility>
 #include <cmath>
 #include <boost/math/tools/precision.hpp>
+#include <boost/math/policy/policy.hpp>
 #include <boost/cstdint.hpp>
 
 namespace boost{ namespace math{ namespace tools{
@@ -18,7 +19,7 @@
 std::pair<T, T> brent_find_minima(F f, T min, T max, int bits, boost::uintmax_t& max_iter)
 {
    using namespace std;
- bits = (std::min)(tools::digits<T>() / 2, bits);
+ bits = (std::min)(policy::digits<T, policy::policy<> >() / 2, bits);
    T tolerance = static_cast<T>(ldexp(1.0, 1-bits));
    T x; // minima so far
    T w; // second best point

Modified: sandbox/math_toolkit/boost/math/tools/ntl.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/ntl.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/ntl.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,6 +11,7 @@
 #include <boost/math/tools/real_cast.hpp>
 #include <boost/math/tools/precision.hpp>
 #include <boost/math/constants/constants.hpp>
+#include <boost/math/policy/policy.hpp>
 
 namespace NTL
 {
@@ -59,7 +60,25 @@
 
 } // namespace NTL
 
-namespace boost{ namespace math{ namespace tools{
+namespace boost{ namespace math{
+
+namespace policy{
+
+template<>
+inline int digits<NTL::RR, boost::math::policy::policy<> >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::RR))
+{
+ return NTL::RR::precision();
+}
+
+template<>
+inline int digits<NTL::RR, boost::math::policy::policy<boost::math::policy::detail::forwarding_arg1, boost::math::policy::detail::forwarding_arg2> >(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::RR))
+{
+ return NTL::RR::precision();
+}
+
+}
+
+namespace tools{
 
 template <>
 inline float real_cast<float, NTL::RR>(NTL::RR t)
@@ -105,12 +124,6 @@
    return static_cast<int>(real_cast<long double>(t));;
 }
 
-template<>
-inline int digits<NTL::RR>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::RR))
-{
- return NTL::RR::precision();
-}
-
 template <>
 inline NTL::RR max_value<NTL::RR>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::RR))
 {
@@ -172,7 +185,7 @@
 template <>
 inline NTL::RR epsilon<NTL::RR>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::RR))
 {
- return ldexp(NTL::RR(1), 1-digits<NTL::RR>());
+ return ldexp(NTL::RR(1), 1-boost::math::policy::digits<NTL::RR, boost::math::policy::policy<> >());
 }
 
 } // namespace tools
@@ -229,12 +242,6 @@
    return to_quad_float(t);
 }
 
-template<>
-inline int digits<NTL::quad_float>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::quad_float))
-{
- return 106;
-}
-
 template <>
 inline NTL::quad_float max_value<NTL::quad_float>(BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(NTL::quad_float))
 {
@@ -297,7 +304,7 @@
          NTL::RR(std::asin(boost::math::tools::real_cast<double>(z))),
          NTL::RR(-boost::math::constants::pi<NTL::RR>()/2),
          NTL::RR(boost::math::constants::pi<NTL::RR>()/2),
- boost::math::tools::digits<NTL::RR>());
+ boost::math::policy::digits<NTL::RR, boost::math::policy::policy<> >());
    }
 
    struct acos_root
@@ -323,7 +330,7 @@
          NTL::RR(std::acos(boost::math::tools::real_cast<double>(z))),
          NTL::RR(-boost::math::constants::pi<NTL::RR>()/2),
          NTL::RR(boost::math::constants::pi<NTL::RR>()/2),
- boost::math::tools::digits<NTL::RR>());
+ boost::math::policy::digits<NTL::RR, boost::math::policy::policy<> >());
    }
 
    struct atan_root
@@ -350,7 +357,7 @@
          NTL::RR(std::atan(boost::math::tools::real_cast<double>(z))),
          -boost::math::constants::pi<NTL::RR>()/2,
          boost::math::constants::pi<NTL::RR>()/2,
- boost::math::tools::digits<NTL::RR>());
+ boost::math::policy::digits<NTL::RR, boost::math::policy::policy<> >());
    }
 
    inline NTL::RR sinh(NTL::RR z)

Modified: sandbox/math_toolkit/boost/math/tools/precision.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/precision.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/precision.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,6 +12,7 @@
 #include <boost/mpl/int.hpp>
 #include <boost/mpl/bool.hpp>
 #include <boost/mpl/if.hpp>
+#include <boost/math/policy/policy.hpp>
 
 #include <iostream>
 #include <iomanip>
@@ -33,17 +34,6 @@
 // See Conceptual Requirements for Real Number Types.
 
 template <class T>
-inline int digits(BOOST_EXPLICIT_TEMPLATE_TYPE(T))
-{
-#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
-#else
- BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
-#endif
- return std::numeric_limits<T>::digits;
-}
-
-template <class T>
 inline T max_value(BOOST_EXPLICIT_TEMPLATE_TYPE(T))
 {
 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
@@ -163,7 +153,7 @@
 inline T epsilon(const mpl::false_& BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
 {
    using namespace std; // for ADL of std names
- static const T eps = ldexp(static_cast<T>(1), 1-tools::digits<T>());
+ static const T eps = ldexp(static_cast<T>(1), 1-policy::digits<T, policy::policy<> >());
    return eps;
 }
 

Modified: sandbox/math_toolkit/boost/math/tools/promotion.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/promotion.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/promotion.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -26,6 +26,8 @@
 #include <boost/type_traits/remove_cv.hpp>// for boost::remove_cv
 // Boost Template meta programming:
 #include <boost/mpl/if.hpp> // for boost::mpl::if_c.
+#include <boost/mpl/and.hpp> // for boost::mpl::if_c.
+#include <boost/mpl/or.hpp> // for boost::mpl::if_c.
 
 namespace boost
 {
@@ -66,11 +68,11 @@
         typedef typename promote_arg<T1>::type T1P; // T1 perhaps promoted.
         typedef typename promote_arg<T2>::type T2P; // T2 perhaps promoted.
 
- typedef typename mpl::if_c<
- ::boost::is_floating_point<T1P>::value && ::boost::is_floating_point<T2P>::value, // both T1P and T2P are floating-point?
- typename mpl::if_c< ::boost::is_same<long double, T1P>::value || ::boost::is_same<long double, T2P>::value, // either long double?
+ typedef typename mpl::if_<
+ typename mpl::and_<is_floating_point<T1P>, is_floating_point<T2P> >::type, // both T1P and T2P are floating-point?
+ typename mpl::if_< typename mpl::or_<is_same<long double, T1P>, is_same<long double, T2P> >::type, // either long double?
             long double, // then result type is long double.
- typename mpl::if_c< ::boost::is_same<double, T1P>::value || ::boost::is_same<double, T2P>::value, // either double?
+ typename mpl::if_< typename mpl::or_<is_same<double, T1P>, is_same<double, T2P> >::type, // either double?
             double, // result type is double.
           float // else result type is float.
>::type

Modified: sandbox/math_toolkit/boost/math/tools/remez.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/remez.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/remez.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -13,6 +13,7 @@
 #include <boost/function/function1.hpp>
 #include <boost/scoped_array.hpp>
 #include <boost/math/constants/constants.hpp>
+#include <boost/math/policy/policy.hpp>
 
 namespace boost{ namespace math{ namespace tools{
 
@@ -310,12 +311,12 @@
    if(bits == 0)
    {
       // don't bother about more than float precision:
- m_precision = (std::min)(24, (digits<T>() / 2) - 2);
+ m_precision = (std::min)(24, (boost::math::policy::digits<T, boost::math::policy::policy<> >() / 2) - 2);
    }
    else
    {
       // can't be more accurate than half the bits of T:
- m_precision = (std::min)(bits, (digits<T>() / 2) - 2);
+ m_precision = (std::min)(bits, (boost::math::policy::digits<T, boost::math::policy::policy<> >() / 2) - 2);
    }
    m_max_change_history[0] = m_max_change_history[1] = 1;
    init_chebyshev();
@@ -371,12 +372,12 @@
    if(bits == 0)
    {
       // don't bother about more than float precision:
- m_precision = (std::min)(24, (digits<T>() / 2) - 2);
+ m_precision = (std::min)(24, (boost::math::policy::digits<T, boost::math::policy::policy<> >() / 2) - 2);
    }
    else
    {
       // can't be more accurate than half the bits of T:
- m_precision = (std::min)(bits, (digits<T>() / 2) - 2);
+ m_precision = (std::min)(bits, (boost::math::policy::digits<T, boost::math::policy::policy<> >() / 2) - 2);
    }
    m_max_change_history[0] = m_max_change_history[1] = 1;
    // do one iteration whatever:

Modified: sandbox/math_toolkit/boost/math/tools/roots.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/roots.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/roots.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -19,6 +19,7 @@
 #include <boost/throw_exception.hpp>
 #include <boost/math/special_functions/sign.hpp>
 #include <boost/math/tools/toms748_solve.hpp>
+#include <boost/math/policy/error_handling.hpp>
 
 
 #include <utility>
@@ -82,8 +83,8 @@
 
 } // namespace
 
-template <class F, class T, class Tol>
-std::pair<T, T> bisect(F f, T min, T max, Tol tol, boost::uintmax_t& max_iter)
+template <class F, class T, class Tol, class Policy>
+std::pair<T, T> bisect(F f, T min, T max, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
 {
    T fmin = f(min);
    T fmax = f(max);
@@ -95,15 +96,16 @@
    //
    // Error checking:
    //
+ static const char* function = "boost::math::tools::bisect<%1%>";
    if(min >= max)
    {
- tools::logic_error(BOOST_CURRENT_FUNCTION,
- "Arguments in wrong order in boost::math::tools::bisect (first arg=%1%)", min);
+ policy::raise_evaluation_error(function,
+ "Arguments in wrong order in boost::math::tools::bisect (first arg=%1%)", min, pol);
    }
    if(fmin * fmax >= 0)
    {
- tools::logic_error(BOOST_CURRENT_FUNCTION,
- "No change of sign in boost::math::tools::bisect, either there is no root to find, or there are multiple roots in the interval (f(min) = %1%).", fmin);
+ policy::raise_evaluation_error(function,
+ "No change of sign in boost::math::tools::bisect, either there is no root to find, or there are multiple roots in the interval (f(min) = %1%).", fmin, pol);
    }
 
    //
@@ -156,10 +158,16 @@
 }
 
 template <class F, class T, class Tol>
+inline std::pair<T, T> bisect(F f, T min, T max, Tol tol, boost::uintmax_t& max_iter)
+{
+ return bisect(f, min, max, tol, max_iter, policy::policy<>());
+}
+
+template <class F, class T, class Tol>
 inline std::pair<T, T> bisect(F f, T min, T max, Tol tol)
 {
    boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)();
- return bisect(f, min, max, tol, m);
+ return bisect(f, min, max, tol, m, policy::policy<>());
 }
 
 template <class F, class T>

Modified: sandbox/math_toolkit/boost/math/tools/test.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/test.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/test.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -10,6 +10,7 @@
 #include <boost/math/tools/stats.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/test/test_tools.hpp>
+#include <stdexcept>
 
 namespace boost{ namespace math{ namespace tools{
 
@@ -177,9 +178,21 @@
    {
       const row_type& row = a[i];
       value_type point;
- try{
+ try
+ {
          point = test_func(row);
- }catch(const std::exception& e)
+ }
+ catch(const std::underflow_error&)
+ {
+ point = 0;
+ }
+ catch(const std::overflow_error&)
+ {
+ point = std::numeric_limits<value_type>::has_infinity ?
+ std::numeric_limits<value_type>::infinity()
+ : tools::max_value<value_type>();
+ }
+ catch(const std::exception& e)
       {
          std::cerr << e.what() << std::endl;
          print_row(row);

Modified: sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -7,7 +7,7 @@
 #define BOOST_MATH_TOOLS_SOLVE_ROOT_HPP
 
 #include <boost/math/tools/precision.hpp>
-#include <boost/math/tools/error_handling.hpp>
+#include <boost/math/policy/error_handling.hpp>
 #include <boost/math/tools/config.hpp>
 #include <boost/math/special_functions/sign.hpp>
 #include <boost/cstdint.hpp>
@@ -55,6 +55,17 @@
    }
 };
 
+struct equal_nearest_integer
+{
+ equal_nearest_integer(){}
+ template <class T>
+ bool operator()(const T& a, const T& b)
+ {
+ using namespace std;
+ return floor(a + 0.5f) == floor(b + 0.5f);
+ }
+};
+
 namespace detail{
 
 template <class F, class T>
@@ -253,8 +264,8 @@
 
 } // namespace detail
 
-template <class F, class T, class Tol>
-std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, const T& fax, const T& fbx, Tol tol, boost::uintmax_t& max_iter)
+template <class F, class T, class Tol, class Policy>
+std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, const T& fax, const T& fbx, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
 {
    //
    // Main entry point and logic for Toms Algorithm 748
@@ -262,6 +273,8 @@
    //
    using namespace std; // For ADL of std math functions
 
+ static const char* function = "boost::math::tools::toms748_solve<%1%>";
+
    boost::uintmax_t count = max_iter;
    T a, b, fa, fb, c, u, fu, a0, b0, d, fd, e, fe;
    static const T mu = 0.5f;
@@ -270,15 +283,26 @@
    a = ax;
    b = bx;
    if(a >= b)
- tools::domain_error(
- BOOST_CURRENT_FUNCTION,
- "Parameters a and b out of order: a=%1%", a);
+ policy::raise_domain_error(
+ function,
+ "Parameters a and b out of order: a=%1%", a, pol);
    fa = fax;
    fb = fbx;
+
+ if(tol(a, b) || (fa == 0) || (fb == 0))
+ {
+ max_iter = 0;
+ if(fa == 0)
+ b = a;
+ else if(fb == 0)
+ a = b;
+ return std::make_pair(a, b);
+ }
+
    if(boost::math::sign(fa) * boost::math::sign(fb) > 0)
- tools::domain_error(
- BOOST_CURRENT_FUNCTION,
- "Parameters a and b do not bracket the root: a=%1%", a);
+ policy::raise_domain_error(
+ function,
+ "Parameters a and b do not bracket the root: a=%1%", a, pol);
    // dummy value for fd, e and fe:
    fe = e = fd = 1e5F;
 
@@ -292,7 +316,7 @@
       --count;
       BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b);
 
- if(count && (fa != 0))
+ if(count && (fa != 0) && !tol(a, b))
       {
          //
          // On the second step we take a quadratic interpolation:
@@ -415,18 +439,31 @@
 }
 
 template <class F, class T, class Tol>
-inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, Tol tol, boost::uintmax_t& max_iter)
+inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, const T& fax, const T& fbx, Tol tol, boost::uintmax_t& max_iter)
+{
+ return toms748_solve(f, ax, bx, fax, fbx, tol, max_iter, policy::policy<>());
+}
+
+template <class F, class T, class Tol, class Policy>
+inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
 {
    max_iter -= 2;
- std::pair<T, T> r = toms748_solve(f, ax, bx, f(ax), f(bx), tol, max_iter);
+ std::pair<T, T> r = toms748_solve(f, ax, bx, f(ax), f(bx), tol, max_iter, pol);
    max_iter += 2;
    return r;
 }
 
 template <class F, class T, class Tol>
-std::pair<T, T> bracket_and_solve_root(F f, const T& guess, const T& factor, bool rising, Tol tol, boost::uintmax_t& max_iter)
+inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, Tol tol, boost::uintmax_t& max_iter)
+{
+ return toms748_solve(f, ax, bx, tol, max_iter, policy::policy<>());
+}
+
+template <class F, class T, class Tol, class Policy>
+std::pair<T, T> bracket_and_solve_root(F f, const T& guess, const T& factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
 {
    using namespace std;
+ static const char* function = "boost::math::tools::bracket_and_solve_root<%1%>";
    //
    // Set up inital brackets:
    //
@@ -448,7 +485,7 @@
       while(sign(fb) == sign(fa))
       {
          if(count == 0)
- tools::logic_error(BOOST_CURRENT_FUNCTION, "Unable to bracket root, last nearest value was %1%", b);
+ policy::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, pol);
          a = b;
          fa = fb;
          b *= factor;
@@ -473,7 +510,7 @@
             return a > 0 ? std::make_pair(T(0), T(a)) : std::make_pair(T(a), T(0));
          }
          if(count == 0)
- tools::logic_error(BOOST_CURRENT_FUNCTION, "Unable to bracket root, last nearest value was %1%", a);
+ policy::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", a, pol);
          b = a;
          fb = fa;
          a /= factor;
@@ -484,12 +521,18 @@
    }
    max_iter -= count;
    max_iter += 1;
- std::pair<T, T> r = toms748_solve(f, a, b, fa, fb, tol, count);
+ std::pair<T, T> r = toms748_solve(f, a, b, fa, fb, tol, count, pol);
    max_iter += count;
    BOOST_MATH_INSTRUMENT_CODE("max_iter = " << max_iter << " count = " << count);
    return r;
 }
 
+template <class F, class T, class Tol>
+inline std::pair<T, T> bracket_and_solve_root(F f, const T& guess, const T& factor, bool rising, Tol tol, boost::uintmax_t& max_iter)
+{
+ return bracket_and_solve_root(f, guess, factor, rising, tol, max_iter, policy::policy<>());
+}
+
 } // namespace tools
 } // namespace math
 } // namespace boost

Modified: sandbox/math_toolkit/libs/math/doc/distributions/binomial.qbk
==============================================================================
--- sandbox/math_toolkit/libs/math/doc/distributions/binomial.qbk (original)
+++ sandbox/math_toolkit/libs/math/doc/distributions/binomial.qbk 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -302,22 +302,22 @@
 [[__ccdf]
    [The probability of obtaining [*more than k successes] from n trials
    with success fraction p. For example:
-
+
 `cdf(complement(binomial(n, p), k))`]]
 [[__quantile]
    [The [*greatest] number of successes that may be observed from n trials
    with success fraction p, at probability P. Note that the value returned
    is a real-number, and not an integer. Depending on the use case you may
    want to take either the floor or ceiling of the result. For example:
-
-
+
 `quantile(binomial(n, p), P)`]]
 [[__quantile_c]
    [The [*smallest] number of successes that may be observed from n trials
    with success fraction p, at probability P. Note that the value returned
    is a real-number, and not an integer. Depending on the use case you may
    want to take either the floor or ceiling of the result. For example:
- ``quantile(complement(binomial(n, p), P))``]]
+
+`quantile(complement(binomial(n, p), P))``]]
 ]
 
 [h4 Examples]

Modified: sandbox/math_toolkit/libs/math/doc/math.qbk
==============================================================================
--- sandbox/math_toolkit/libs/math/doc/math.qbk (original)
+++ sandbox/math_toolkit/libs/math/doc/math.qbk 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -359,6 +359,8 @@
 [include concepts.qbk]
 [endsect][/section:Using_UDT Use with User Defined Floating-Point Types]
 
+[include policy.qbk]
+
 [section:backgrounders Backgrounders]
 [include implementation.qbk]
 [include error.qbk][/relative error NOT handling]

Modified: sandbox/math_toolkit/libs/math/performance/main.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/performance/main.cpp (original)
+++ sandbox/math_toolkit/libs/math/performance/main.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -100,6 +100,7 @@
             if(!found)
             {
                std::cerr << "Unknown option: " << argv[i] << std::endl;
+ show_help();
                return 1;
             }
          }

Modified: sandbox/math_toolkit/libs/math/test/Jamfile.v2
==============================================================================
--- sandbox/math_toolkit/libs/math/test/Jamfile.v2 (original)
+++ sandbox/math_toolkit/libs/math/test/Jamfile.v2 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,6 +12,7 @@
       <toolset>gcc:<cxxflags>-Wno-missing-braces
       <toolset>darwin:<cxxflags>-Wno-missing-braces
       <toolset>acc:<cxxflags>+W2068,2461,2236,4070
+ <toolset>intel:<cxxflags>-Qwd264,239
       <include>../../..
       <source>/boost/regex//boost_regex
       <link>shared:<define>BOOST_REGEX_DYN_LINK=1
@@ -60,8 +61,8 @@
 run test_minima.cpp ;
 run test_negative_binomial.cpp ;
 run test_normal.cpp ;
-run test_poisson.cpp ;
 run test_pareto.cpp ;
+run test_poisson.cpp ;
 run test_rayleigh.cpp ;
 
 run test_rationals.cpp
@@ -95,6 +96,8 @@
 run test_triangular.cpp ;
 run test_uniform.cpp ;
 run test_weibull.cpp ;
+run test_policy.cpp ;
+run test_policy_sf.cpp ;
 
 run test_bessel_j.cpp ;
 run test_bessel_y.cpp ;
@@ -154,8 +157,6 @@
 compile compile_test/sf_sqrt1pm1_incl_test.cpp ;
 compile compile_test/std_real_concept_check.cpp ;
 compile compile_test/tools_config_inc_test.cpp ;
-compile compile_test/tools_error_handling_inc_test.cpp ;
-compile compile_test/tools_evaluation_type_inc_test.cpp ;
 compile compile_test/tools_fraction_inc_test.cpp ;
 compile compile_test/tools_minima_inc_test.cpp ;
 compile compile_test/tools_polynomial_inc_test.cpp ;
@@ -172,5 +173,3 @@
 compile compile_test/tools_toms748_solve_inc_test.cpp ;
 
 
-
-

Modified: sandbox/math_toolkit/libs/math/test/compile_test/distribution_concept_check.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/compile_test/distribution_concept_check.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/compile_test/distribution_concept_check.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,9 +3,12 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
+
 #include <boost/math/concepts/distributions.hpp>
 
 #include <boost/math/distributions/normal.hpp>
+#include <boost/math/distributions/bernoulli.hpp>
 #include <boost/math/distributions/students_t.hpp>
 #include <boost/math/distributions/binomial.hpp>
 #include <boost/math/distributions/cauchy.hpp>
@@ -13,9 +16,16 @@
 #include <boost/math/distributions/exponential.hpp>
 #include <boost/math/distributions/extreme_value.hpp>
 #include <boost/math/distributions/fisher_f.hpp>
+#include <boost/math/distributions/gamma.hpp>
 #include <boost/math/distributions/pareto.hpp>
+#include <boost/math/distributions/rayleigh.hpp>
 #include <boost/math/distributions/weibull.hpp>
 #include <boost/math/distributions/lognormal.hpp>
+#include <boost/math/distributions/triangular.hpp>
+#include <boost/math/distributions/uniform.hpp>
+#include <boost/math/distributions/poisson.hpp>
+#include <boost/math/distributions/beta.hpp>
+#include <boost/math/distributions/negative_binomial.hpp>
 
 template <class RealType>
 void instantiate(RealType)
@@ -25,16 +35,24 @@
    using namespace boost::math::concepts;
 
    function_requires<DistributionConcept<normal_distribution<RealType> > >();
+ function_requires<DistributionConcept<beta_distribution<RealType> > >();
    function_requires<DistributionConcept<binomial_distribution<RealType> > >();
    function_requires<DistributionConcept<cauchy_distribution<RealType> > >();
+ function_requires<DistributionConcept<bernoulli_distribution<RealType> > >();
    function_requires<DistributionConcept<chi_squared_distribution<RealType> > >();
    function_requires<DistributionConcept<exponential_distribution<RealType> > >();
    function_requires<DistributionConcept<extreme_value_distribution<RealType> > >();
    function_requires<DistributionConcept<fisher_f_distribution<RealType> > >();
+ function_requires<DistributionConcept<gamma_distribution<RealType> > >();
    function_requires<DistributionConcept<students_t_distribution<RealType> > >();
    function_requires<DistributionConcept<pareto_distribution<RealType> > >();
+ function_requires<DistributionConcept<poisson_distribution<RealType> > >();
+ function_requires<DistributionConcept<rayleigh_distribution<RealType> > >();
    function_requires<DistributionConcept<weibull_distribution<RealType> > >();
    function_requires<DistributionConcept<lognormal_distribution<RealType> > >();
+ function_requires<DistributionConcept<triangular_distribution<RealType> > >();
+ function_requires<DistributionConcept<uniform_distribution<RealType> > >();
+ function_requires<DistributionConcept<negative_binomial_distribution<RealType> > >();
 }
 
 

Modified: sandbox/math_toolkit/libs/math/test/compile_test/instantiate.hpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/compile_test/instantiate.hpp (original)
+++ sandbox/math_toolkit/libs/math/test/compile_test/instantiate.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -7,51 +7,29 @@
 #ifndef BOOST_LIBS_MATH_TEST_INSTANTIATE_HPP
 #define BOOST_LIBS_MATH_TEST_INSTANTIATE_HPP
 
-#include <boost/math/distributions/bernoulli.hpp>
-#include <boost/math/distributions/beta.hpp>
-#include <boost/math/distributions/binomial.hpp>
-#include <boost/math/distributions/cauchy.hpp>
-#include <boost/math/distributions/chi_squared.hpp>
-#include <boost/math/distributions/exponential.hpp>
-#include <boost/math/distributions/extreme_value.hpp>
-#include <boost/math/distributions/fisher_f.hpp>
-#include <boost/math/distributions/gamma.hpp>
-#include <boost/math/distributions/lognormal.hpp>
-#include <boost/math/distributions/negative_binomial.hpp>
-#include <boost/math/distributions/normal.hpp>
-#include <boost/math/distributions/pareto.hpp>
-#include <boost/math/distributions/poisson.hpp>
-#include <boost/math/distributions/rayleigh.hpp>
-#include <boost/math/distributions/students_t.hpp>
-#include <boost/math/distributions/triangular.hpp>
-#include <boost/math/distributions/uniform.hpp>
-#include <boost/math/distributions/weibull.hpp>
-
-#include <boost/math/special_functions/digamma.hpp>
-#include <boost/math/special_functions/cbrt.hpp>
-#include <boost/math/special_functions/legendre.hpp>
-#include <boost/math/special_functions/laguerre.hpp>
-#include <boost/math/special_functions/hermite.hpp>
-#include <boost/math/special_functions/spherical_harmonic.hpp>
-#include <boost/math/special_functions/ellint_1.hpp>
-#include <boost/math/special_functions/ellint_2.hpp>
-#include <boost/math/special_functions/ellint_3.hpp>
-#include <boost/math/special_functions/ellint_rc.hpp>
-#include <boost/math/special_functions/ellint_rd.hpp>
-#include <boost/math/special_functions/ellint_rf.hpp>
-#include <boost/math/special_functions/ellint_rj.hpp>
-#include <boost/math/special_functions/hypot.hpp>
-#include <boost/math/special_functions/sinc.hpp>
-#include <boost/math/special_functions/sinhc.hpp>
-#include <boost/math/special_functions/asinh.hpp>
-#include <boost/math/special_functions/acosh.hpp>
-#include <boost/math/special_functions/atanh.hpp>
-#include <boost/math/special_functions/sin_pi.hpp>
-#include <boost/math/special_functions/cos_pi.hpp>
-#include <boost/math/special_functions/bessel.hpp>
+#ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY
+# define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
+#endif
 
+#include <boost/math/distributions.hpp>
+
+#include <boost/math/special_functions.hpp>
 #include <boost/math/concepts/distributions.hpp>
 
+typedef boost::math::policy::policy<> test_policy;
+
+namespace test{
+
+BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(test_policy)
+
+}
+
+namespace dist_test{
+
+BOOST_MATH_DECLARE_DISTRIBUTIONS(double, test_policy)
+
+}
+
 template <class RealType>
 void instantiate(RealType)
 {
@@ -79,6 +57,46 @@
    function_requires<DistributionConcept<uniform_distribution<RealType> > >();
    function_requires<DistributionConcept<weibull_distribution<RealType> > >();
 
+ function_requires<DistributionConcept<bernoulli_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<beta_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<binomial_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<cauchy_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<chi_squared_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<exponential_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<extreme_value_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<fisher_f_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<gamma_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<lognormal_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<negative_binomial_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<normal_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<rayleigh_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<pareto_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<poisson_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<students_t_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<triangular_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<uniform_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<weibull_distribution<RealType, test_policy> > >();
+
+ function_requires<DistributionConcept<dist_test::bernoulli > >();
+ function_requires<DistributionConcept<dist_test::beta > >();
+ function_requires<DistributionConcept<dist_test::binomial > >();
+ function_requires<DistributionConcept<dist_test::cauchy > >();
+ function_requires<DistributionConcept<dist_test::chi_squared > >();
+ function_requires<DistributionConcept<dist_test::exponential > >();
+ function_requires<DistributionConcept<dist_test::extreme_value > >();
+ function_requires<DistributionConcept<dist_test::fisher_f > >();
+ function_requires<DistributionConcept<dist_test::gamma > >();
+ function_requires<DistributionConcept<dist_test::lognormal > >();
+ function_requires<DistributionConcept<dist_test::negative_binomial > >();
+ function_requires<DistributionConcept<dist_test::normal > >();
+ function_requires<DistributionConcept<dist_test::rayleigh > >();
+ function_requires<DistributionConcept<dist_test::pareto > >();
+ function_requires<DistributionConcept<dist_test::poisson > >();
+ function_requires<DistributionConcept<dist_test::students_t > >();
+ function_requires<DistributionConcept<dist_test::triangular > >();
+ function_requires<DistributionConcept<dist_test::uniform > >();
+ function_requires<DistributionConcept<dist_test::weibull > >();
+
    int i;
    RealType v1(0.5), v2(0.5), v3(0.5);
    boost::math::tgamma(v1);
@@ -172,6 +190,195 @@
    boost::math::sph_bessel(i, 1);
    boost::math::sph_neumann(i, v2);
    boost::math::sph_neumann(i, i);
+ //
+ // All over again, with a policy this time:
+ //
+ test_policy pol;
+ boost::math::tgamma(v1, pol);
+ boost::math::tgamma1pm1(v1, pol);
+ boost::math::lgamma(v1, pol);
+ boost::math::lgamma(v1, &i, pol);
+ boost::math::digamma(v1, pol);
+ boost::math::tgamma_ratio(v1, v2, pol);
+ boost::math::tgamma_delta_ratio(v1, v2, pol);
+ boost::math::factorial<RealType>(i, pol);
+ boost::math::unchecked_factorial<RealType>(i);
+ i = boost::math::max_factorial<RealType>::value;
+ boost::math::double_factorial<RealType>(i, pol);
+ boost::math::rising_factorial(v1, i, pol);
+ boost::math::falling_factorial(v1, i, pol);
+ boost::math::tgamma(v1, v2, pol);
+ boost::math::tgamma_lower(v1, v2, pol);
+ boost::math::gamma_p(v1, v2, pol);
+ boost::math::gamma_q(v1, v2, pol);
+ boost::math::gamma_p_inv(v1, v2, pol);
+ boost::math::gamma_q_inv(v1, v2, pol);
+ boost::math::gamma_p_inva(v1, v2, pol);
+ boost::math::gamma_q_inva(v1, v2, pol);
+ boost::math::erf(v1, pol);
+ boost::math::erfc(v1, pol);
+ boost::math::erf_inv(v1, pol);
+ boost::math::erfc_inv(v1, pol);
+ boost::math::beta(v1, v2, pol);
+ boost::math::beta(v1, v2, v3, pol);
+ boost::math::betac(v1, v2, v3, pol);
+ boost::math::ibeta(v1, v2, v3, pol);
+ boost::math::ibetac(v1, v2, v3, pol);
+ boost::math::ibeta_inv(v1, v2, v3, pol);
+ boost::math::ibetac_inv(v1, v2, v3, pol);
+ boost::math::ibeta_inva(v1, v2, v3, pol);
+ boost::math::ibetac_inva(v1, v2, v3, pol);
+ boost::math::ibeta_invb(v1, v2, v3, pol);
+ boost::math::ibetac_invb(v1, v2, v3, pol);
+ boost::math::gamma_p_derivative(v2, v3, pol);
+ boost::math::ibeta_derivative(v1, v2, v3, pol);
+ boost::math::fpclassify(v1);
+ boost::math::isfinite(v1);
+ boost::math::isnormal(v1);
+ boost::math::isnan(v1);
+ boost::math::isinf(v1);
+ boost::math::log1p(v1, pol);
+ boost::math::expm1(v1, pol);
+ boost::math::cbrt(v1, pol);
+ boost::math::sqrt1pm1(v1, pol);
+ boost::math::powm1(v1, v2, pol);
+ boost::math::legendre_p(1, v1, pol);
+ boost::math::legendre_p(1, 0, v1, pol);
+ boost::math::legendre_q(1, v1, pol);
+ boost::math::legendre_next(2, v1, v2, v3);
+ boost::math::legendre_next(2, 2, v1, v2, v3);
+ boost::math::laguerre(1, v1, pol);
+ boost::math::laguerre(2, 1, v1, pol);
+ boost::math::laguerre_next(2, v1, v2, v3);
+ boost::math::laguerre_next(2, 1, v1, v2, v3);
+ boost::math::hermite(1, v1, pol);
+ boost::math::hermite_next(2, v1, v2, v3);
+ boost::math::spherical_harmonic_r(2, 1, v1, v2, pol);
+ boost::math::spherical_harmonic_i(2, 1, v1, v2, pol);
+ boost::math::ellint_1(v1, pol);
+ boost::math::ellint_1(v1, v2, pol);
+ boost::math::ellint_2(v1, pol);
+ boost::math::ellint_2(v1, v2, pol);
+ boost::math::ellint_3(v1, v2, pol);
+ boost::math::ellint_3(v1, v2, v3, pol);
+ boost::math::ellint_rc(v1, v2, pol);
+ boost::math::ellint_rd(v1, v2, v3, pol);
+ boost::math::ellint_rf(v1, v2, v3, pol);
+ boost::math::ellint_rj(v1, v2, v3, v1, pol);
+ boost::math::hypot(v1, v2, pol);
+ boost::math::sinc_pi(v1, pol);
+ boost::math::sinhc_pi(v1, pol);
+ boost::math::asinh(v1, pol);
+ boost::math::acosh(v1, pol);
+ boost::math::atanh(v1, pol);
+ boost::math::sin_pi(v1, pol);
+ boost::math::cos_pi(v1, pol);
+ boost::math::cyl_neumann(v1, v2, pol);
+ boost::math::cyl_neumann(i, v2, pol);
+ boost::math::cyl_bessel_j(v1, v2, pol);
+ boost::math::cyl_bessel_j(i, v2, pol);
+ boost::math::cyl_bessel_i(v1, v2, pol);
+ boost::math::cyl_bessel_i(i, v2, pol);
+ boost::math::cyl_bessel_k(v1, v2, pol);
+ boost::math::cyl_bessel_k(i, v2, pol);
+ boost::math::sph_bessel(i, v2, pol);
+ boost::math::sph_bessel(i, 1, pol);
+ boost::math::sph_neumann(i, v2, pol);
+ boost::math::sph_neumann(i, i, pol);
+ //
+ // All over again with the versions in test::
+ //
+ test::tgamma(v1);
+ test::tgamma1pm1(v1);
+ test::lgamma(v1);
+ test::lgamma(v1, &i);
+ test::digamma(v1);
+ test::tgamma_ratio(v1, v2);
+ test::tgamma_delta_ratio(v1, v2);
+ test::factorial<RealType>(i);
+ test::unchecked_factorial<RealType>(i);
+ i = test::max_factorial<RealType>::value;
+ test::double_factorial<RealType>(i);
+ test::rising_factorial(v1, i);
+ test::falling_factorial(v1, i);
+ test::tgamma(v1, v2);
+ test::tgamma_lower(v1, v2);
+ test::gamma_p(v1, v2);
+ test::gamma_q(v1, v2);
+ test::gamma_p_inv(v1, v2);
+ test::gamma_q_inv(v1, v2);
+ test::gamma_p_inva(v1, v2);
+ test::gamma_q_inva(v1, v2);
+ test::erf(v1);
+ test::erfc(v1);
+ test::erf_inv(v1);
+ test::erfc_inv(v1);
+ test::beta(v1, v2);
+ test::beta(v1, v2, v3);
+ test::betac(v1, v2, v3);
+ test::ibeta(v1, v2, v3);
+ test::ibetac(v1, v2, v3);
+ test::ibeta_inv(v1, v2, v3);
+ test::ibetac_inv(v1, v2, v3);
+ test::ibeta_inva(v1, v2, v3);
+ test::ibetac_inva(v1, v2, v3);
+ test::ibeta_invb(v1, v2, v3);
+ test::ibetac_invb(v1, v2, v3);
+ test::gamma_p_derivative(v2, v3);
+ test::ibeta_derivative(v1, v2, v3);
+ test::fpclassify(v1);
+ test::isfinite(v1);
+ test::isnormal(v1);
+ test::isnan(v1);
+ test::isinf(v1);
+ test::log1p(v1);
+ test::expm1(v1);
+ test::cbrt(v1);
+ test::sqrt1pm1(v1);
+ test::powm1(v1, v2);
+ test::legendre_p(1, v1);
+ test::legendre_p(1, 0, v1);
+ test::legendre_q(1, v1);
+ test::legendre_next(2, v1, v2, v3);
+ test::legendre_next(2, 2, v1, v2, v3);
+ test::laguerre(1, v1);
+ test::laguerre(2, 1, v1);
+ test::laguerre_next(2, v1, v2, v3);
+ test::laguerre_next(2, 1, v1, v2, v3);
+ test::hermite(1, v1);
+ test::hermite_next(2, v1, v2, v3);
+ test::spherical_harmonic_r(2, 1, v1, v2);
+ test::spherical_harmonic_i(2, 1, v1, v2);
+ test::ellint_1(v1);
+ test::ellint_1(v1, v2);
+ test::ellint_2(v1);
+ test::ellint_2(v1, v2);
+ test::ellint_3(v1, v2);
+ test::ellint_3(v1, v2, v3);
+ test::ellint_rc(v1, v2);
+ test::ellint_rd(v1, v2, v3);
+ test::ellint_rf(v1, v2, v3);
+ test::ellint_rj(v1, v2, v3, v1);
+ test::hypot(v1, v2);
+ test::sinc_pi(v1);
+ test::sinhc_pi(v1);
+ test::asinh(v1);
+ test::acosh(v1);
+ test::atanh(v1);
+ test::sin_pi(v1);
+ test::cos_pi(v1);
+ test::cyl_neumann(v1, v2);
+ test::cyl_neumann(i, v2);
+ test::cyl_bessel_j(v1, v2);
+ test::cyl_bessel_j(i, v2);
+ test::cyl_bessel_i(v1, v2);
+ test::cyl_bessel_i(i, v2);
+ test::cyl_bessel_k(v1, v2);
+ test::cyl_bessel_k(i, v2);
+ test::sph_bessel(i, v2);
+ test::sph_bessel(i, 1);
+ test::sph_neumann(i, v2);
+ test::sph_neumann(i, i);
 }
 
 

Modified: sandbox/math_toolkit/libs/math/test/compile_test/std_real_concept_check.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/compile_test/std_real_concept_check.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/compile_test/std_real_concept_check.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,8 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
+
 #include <boost/math/concepts/std_real_concept.hpp>
 #include <boost/math/concepts/distributions.hpp>
 

Deleted: sandbox/math_toolkit/libs/math/test/compile_test/tools_error_handling_inc_test.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/compile_test/tools_error_handling_inc_test.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,10 +0,0 @@
-// Copyright John Maddock 2006.
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-// Basic sanity check that header <boost/math/tools/error_handling.hpp>
-// #includes all the files that it needs to.
-//
-#include <boost/math/tools/error_handling.hpp>
-

Deleted: sandbox/math_toolkit/libs/math/test/compile_test/tools_evaluation_type_inc_test.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/compile_test/tools_evaluation_type_inc_test.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
+++ (empty file)
@@ -1,10 +0,0 @@
-// Copyright John Maddock 2006.
-// Use, modification and distribution are subject to the
-// Boost Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-// Basic sanity check that header <boost/math/tools/evaluation_type.hpp>
-// #includes all the files that it needs to.
-//
-#include <boost/math/tools/evaluation_type.hpp>
-

Modified: sandbox/math_toolkit/libs/math/test/hypot_test.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/hypot_test.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/hypot_test.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,7 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/math/special_functions/hypot.hpp>

Modified: sandbox/math_toolkit/libs/math/test/log1p_expm1_test.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/log1p_expm1_test.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/log1p_expm1_test.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,14 +3,18 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
+
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/math/special_functions/log1p.hpp>
 #include <boost/math/special_functions/expm1.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "handle_test_result.hpp"
 
@@ -65,6 +69,7 @@
 template <class T>
 void do_test(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -96,6 +101,7 @@
       boost::lambda::ret<value_type>(boost::lambda::_1[2]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::expm1", "log1p and expm1");
    std::cout << std::endl;
+#endif
 }
 
 template <class T>

Modified: sandbox/math_toolkit/libs/math/test/test_bernoulli.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_bernoulli.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_bernoulli.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -276,4 +276,5 @@
 *** No errors detected
 
 
-*/
\ No newline at end of file
+*/
+

Modified: sandbox/math_toolkit/libs/math/test/test_bessel_i.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_bessel_i.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_bessel_i.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,7 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
@@ -46,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_bessel_j.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_bessel_j.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_bessel_j.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -46,7 +46,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double|real_concept";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_bessel_k.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_bessel_k.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_bessel_k.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,7 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
@@ -46,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_bessel_y.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_bessel_y.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_bessel_y.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,7 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
@@ -46,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double|real_concept";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_beta.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_beta.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_beta.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,8 +12,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_beta_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -112,6 +114,7 @@
 template <class T>
 void do_test_beta(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -146,6 +149,7 @@
    }
 #endif
    std::cout << std::endl;
+#endif
 }
 template <class T>
 void test_beta(T, const char* name)
@@ -194,7 +198,9 @@
    test_spots(0.0);
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_spots(0.0L);
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_spots(boost::math::concepts::real_concept(0.1));
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "
@@ -207,8 +213,10 @@
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_beta(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_binomial.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_binomial.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_binomial.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,6 +11,7 @@
 // Basic sanity test for Binomial Cumulative Distribution Function.
 
 #define BOOST_MATH_THROW_ON_DOMAIN_ERROR
+#define BOOST_MATH_DISCRETE_QUANTILE_POLICY real
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // conditional expression is constant.
@@ -618,6 +619,70 @@
     //7 0.00036621093749999984 0.9999847412109375
     //8 1.52587890625e-005 1 1 0
   }
+#define T RealType
+#include "binomial_quantile.ipp"
+
+ for(unsigned i = 0; i < binomial_quantile_data.size(); ++i)
+ {
+ using namespace boost::math::policy;
+ typedef policy<discrete_quantile<boost::math::policy::real> > P1;
+ typedef policy<discrete_quantile<integer_below> > P2;
+ typedef policy<discrete_quantile<integer_above> > P3;
+ typedef policy<discrete_quantile<integer_outside> > P4;
+ typedef policy<discrete_quantile<integer_inside> > P5;
+ typedef policy<discrete_quantile<integer_nearest> > P6;
+ RealType tol = boost::math::tools::epsilon<RealType>() * 500;
+ if(!boost::is_floating_point<RealType>::value)
+ tol *= 10; // no lanczos approximation implies less accuracy
+ //
+ // Check full real value first:
+ //
+ binomial_distribution<RealType, P1> p1(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ RealType x = quantile(p1, binomial_quantile_data[i][2]);
+ BOOST_CHECK_CLOSE_FRACTION(x, binomial_quantile_data[i][3], tol);
+ x = quantile(complement(p1, binomial_quantile_data[i][2]));
+ BOOST_CHECK_CLOSE_FRACTION(x, binomial_quantile_data[i][4], tol);
+ //
+ // Now with round down to integer:
+ //
+ binomial_distribution<RealType, P2> p2(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ x = quantile(p2, binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, floor(binomial_quantile_data[i][3]));
+ x = quantile(complement(p2, binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, floor(binomial_quantile_data[i][4]));
+ //
+ // Now with round up to integer:
+ //
+ binomial_distribution<RealType, P3> p3(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ x = quantile(p3, binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, ceil(binomial_quantile_data[i][3]));
+ x = quantile(complement(p3, binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, ceil(binomial_quantile_data[i][4]));
+ //
+ // Now with round to integer "outside":
+ //
+ binomial_distribution<RealType, P4> p4(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ x = quantile(p4, binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, binomial_quantile_data[i][2] < 0.5f ? floor(binomial_quantile_data[i][3]) : ceil(binomial_quantile_data[i][3]));
+ x = quantile(complement(p4, binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, binomial_quantile_data[i][2] < 0.5f ? ceil(binomial_quantile_data[i][4]) : floor(binomial_quantile_data[i][4]));
+ //
+ // Now with round to integer "inside":
+ //
+ binomial_distribution<RealType, P5> p5(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ x = quantile(p5, binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, binomial_quantile_data[i][2] < 0.5f ? ceil(binomial_quantile_data[i][3]) : floor(binomial_quantile_data[i][3]));
+ x = quantile(complement(p5, binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, binomial_quantile_data[i][2] < 0.5f ? floor(binomial_quantile_data[i][4]) : ceil(binomial_quantile_data[i][4]));
+ //
+ // Now with round to nearest integer:
+ //
+ binomial_distribution<RealType, P6> p6(binomial_quantile_data[i][0], binomial_quantile_data[i][1]);
+ x = quantile(p6, binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, floor(binomial_quantile_data[i][3] + 0.5f));
+ x = quantile(complement(p6, binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, floor(binomial_quantile_data[i][4] + 0.5f));
+ }
 
 } // template <class RealType>void test_spots(RealType)
 

Modified: sandbox/math_toolkit/libs/math/test/test_binomial_coeff.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_binomial_coeff.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_binomial_coeff.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -43,7 +43,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_carlson.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_carlson.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_carlson.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -53,7 +53,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -67,7 +67,7 @@
    //
    // real long doubles:
    //
- if(boost::math::tools::digits<long double>() > 53)
+ if(boost::math::policy::digits<long double, boost::math::policy::policy<> >() > 53)
    {
       add_expected_result(
          ".*", // compiler

Modified: sandbox/math_toolkit/libs/math/test/test_cauchy.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_cauchy.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_cauchy.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,6 +9,7 @@
 
 #define BOOST_MATH_THROW_ON_DOMAIN_ERROR
 #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR
+#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // conditional expression is constant.

Modified: sandbox/math_toolkit/libs/math/test/test_chi_squared.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_chi_squared.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_chi_squared.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -577,3 +577,4 @@
 
 */
 
+

Modified: sandbox/math_toolkit/libs/math/test/test_ellint_1.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ellint_1.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ellint_1.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -46,7 +46,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_ellint_2.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ellint_2.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ellint_2.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -45,7 +45,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_ellint_3.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ellint_3.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ellint_3.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -48,7 +48,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_erf.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_erf.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_erf.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,8 +11,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_erf_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -107,6 +109,7 @@
 template <class T>
 void do_test_erf(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -160,11 +163,13 @@
    }
 #endif
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
 void do_test_erf_inv(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -185,11 +190,13 @@
       boost::lambda::ret<value_type>(boost::lambda::_1[1]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::erf_inv", test_name);
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
 void do_test_erfc_inv(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -210,6 +217,7 @@
       boost::lambda::ret<value_type>(boost::lambda::_1[1]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::erfc_inv", test_name);
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
@@ -300,8 +308,10 @@
    test_spots(0.0, "double");
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_spots(0.0L, "long double");
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 
    expected_results();
 
@@ -310,8 +320,10 @@
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_erf(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_erf(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_error_handling.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_error_handling.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_error_handling.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -1,6 +1,3 @@
-// test_error_handling.cpp
-
-// Test error handling.
 
 // Copyright Paul A. Bristow 2006.
 // Copyright John Maddock 2006.
@@ -10,80 +7,117 @@
 // (See accompanying file LICENSE_1_0.txt
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-#define BOOST_MATH_THROW_ON_DOMAIN_ERROR
+//
+// Define some custom error handlers:
+//
+struct user_defined_error{};
 
-// Boost
-#include <boost/math/tools/error_handling.hpp> // for domain_error.
- using ::boost::math::tools::domain_error;
- using ::boost::math::tools::pole_error;
- using ::boost::math::tools::overflow_error;
- using ::boost::math::tools::underflow_error;
- using ::boost::math::tools::denorm_error;
- using ::boost::math::tools::logic_error;
-#include <boost/math/special_functions/gamma.hpp> // tgamma
- using ::boost::math::tgamma;
-#include <boost/math/special_functions/fpclassify.hpp>
- using boost::math::isnan;
-// std
-#include <iostream>
- using std::cout;
- using std::endl;
-#include <limits>
- using std::numeric_limits;
-#include <stdexcept>
- using std::exception;
+namespace boost{ namespace math{ namespace policy{
 
-#include <boost/test/included/test_exec_monitor.hpp> // for test_main
-#include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
+template <class T>
+T user_domain_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
 
-#include <boost/math/concepts/real_concept.hpp> // for real_concept
- using ::boost::math::concepts::real_concept;
+template <class T>
+T user_pole_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
 
+template <class T>
+T user_overflow_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
+
+template <class T>
+T user_underflow_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
+
+template <class T>
+T user_denorm_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
+
+template <class T>
+T user_evaluation_error(const char* , const char* , const T& )
+{
+ throw user_defined_error();
+}
+
+}}} // namespaces
+
+
+#include <boost/math/policy/policy.hpp>
+#include <boost/math/policy/error_handling.hpp>
+#include <boost/math/concepts/real_concept.hpp>
+#include <boost/test/included/test_exec_monitor.hpp> // for test_main
 //
-// The macro BOOST_CHECK_THROW_MSG is the same as BOOST_CHECK_THROW
-// which is to say it verifies that the exception we expect is
-// thrown from the function under test, but it also prints the message
-// contained in the thrown exception so we can manually inspect the
-// quality of the message.
-//
-// The expanded code is:
-//
-// try
-// {
-// code;
-// }
-// catch(const std::exception& e)
-// {
-// std::cout <<
-// "Message from thrown exception was:\n " << e.what() << std::endl;
-// }
-// BOOST_CHECK_THROW(code, t);
+// Define some policies:
 //
-#define BOOST_CHECK_THROW_MSG(code,t)\
- try{ code; } catch(const std::exception& e){\
- std::cout << "Message from thrown exception was:\n " << e.what() << std::endl; }\
- BOOST_CHECK_THROW(code, t);
-
-template <class FPT> // Any floating-point type FPT.
-void test_error(FPT)
-{
- cout << "Current function is " << BOOST_CURRENT_FUNCTION << endl;
-// 2 argument version now removed, so these two commented out.
-// BOOST_CHECK_THROW_MSG(domain_error<FPT>(BOOST_CURRENT_FUNCTION, 0), std::domain_error);
-// BOOST_CHECK_THROW_MSG(domain_error<FPT>(BOOST_CURRENT_FUNCTION, "Out of range argument"), std::domain_error);
- BOOST_CHECK_THROW_MSG(domain_error<FPT>(BOOST_CURRENT_FUNCTION, 0, static_cast<FPT>(3.124567890123456789012345678901L)), std::domain_error);
- BOOST_CHECK_THROW_MSG(domain_error<FPT>(BOOST_CURRENT_FUNCTION, "Out of range argument %1% in test invocation", static_cast<FPT>(3.124567890123456789012345678901L)), std::domain_error);
-// BOOST_CHECK_THROW_MSG(logic_error<FPT>(BOOST_CURRENT_FUNCTION, 0), std::logic_error);
-// BOOST_CHECK_THROW_MSG(logic_error<FPT>(BOOST_CURRENT_FUNCTION, "Internal error"), std::logic_error);
- BOOST_CHECK_THROW_MSG(logic_error<FPT>(BOOST_CURRENT_FUNCTION, 0, static_cast<FPT>(3.124567890123456789012345678901L)), std::logic_error);
- BOOST_CHECK_THROW_MSG(logic_error<FPT>(BOOST_CURRENT_FUNCTION, "Internal error, computed result was %1%, but should be in the range [0,1]", static_cast<FPT>(3.124567890123456789012345678901L)), std::logic_error);
- BOOST_CHECK_THROW_MSG(boost::math::tgamma(static_cast<FPT>(0)), std::domain_error);
- BOOST_CHECK_THROW_MSG(boost::math::tgamma(static_cast<FPT>(-10)), std::domain_error);
- BOOST_CHECK_THROW_MSG(boost::math::tgamma(static_cast<FPT>(-10123457772243.0)), std::domain_error);
+using namespace boost::math::policy;
+policy<
+ domain_error<throw_on_error>,
+ pole_error<throw_on_error>,
+ overflow_error<throw_on_error>,
+ underflow_error<throw_on_error>,
+ denorm_error<throw_on_error>,
+ evaluation_error<throw_on_error> > throw_policy;
+policy<
+ domain_error<errno_on_error>,
+ pole_error<errno_on_error>,
+ overflow_error<errno_on_error>,
+ underflow_error<errno_on_error>,
+ denorm_error<errno_on_error>,
+ evaluation_error<errno_on_error> > errno_policy;
+policy<
+ domain_error<user_error>,
+ pole_error<user_error>,
+ overflow_error<user_error>,
+ underflow_error<user_error>,
+ denorm_error<user_error>,
+ evaluation_error<user_error> > user_policy;
+policy<> default_policy;
+
+#define TEST_EXCEPTION(expression, exception)\
+ BOOST_CHECK_THROW(expression, exception);\
+ try{ expression; }catch(const exception& e){ std::cout << e.what() << std::endl; }
 
- cout << endl;
+template <class T>
+void test_error(T)
+{
+ const char* func = "boost::math::test_function<%1%>(%1%, %1%, %1%)";
+ const char* msg1 = "Error while handling value %1%";
+ const char* msg2 = "Error message goes here...";
+
+ TEST_EXCEPTION(boost::math::policy::raise_domain_error(func, msg1, T(0.0), throw_policy), std::domain_error);
+ TEST_EXCEPTION(boost::math::policy::raise_domain_error(func, 0, T(0.0), throw_policy), std::domain_error);
+ TEST_EXCEPTION(boost::math::policy::raise_pole_error(func, msg1, T(0.0), throw_policy), std::domain_error);
+ TEST_EXCEPTION(boost::math::policy::raise_pole_error(func, 0, T(0.0), throw_policy), std::domain_error);
+ TEST_EXCEPTION(boost::math::policy::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_underflow_error<T>(func, msg2, throw_policy), std::underflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_underflow_error<T>(func, 0, throw_policy), std::underflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_denorm_error<T>(func, msg2, T(0), throw_policy), std::underflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_denorm_error<T>(func, 0, T(0), throw_policy), std::underflow_error);
+ TEST_EXCEPTION(boost::math::policy::raise_evaluation_error(func, msg1, T(1.25), throw_policy), boost::math::evaluation_error);
+ TEST_EXCEPTION(boost::math::policy::raise_evaluation_error(func, 0, T(1.25), throw_policy), boost::math::evaluation_error);
+ //
+ // Now try user error handlers: these should all throw user_error():
+ //
+ BOOST_CHECK_THROW(boost::math::policy::raise_domain_error(func, msg1, T(0.0), user_policy), user_defined_error);
+ BOOST_CHECK_THROW(boost::math::policy::raise_pole_error(func, msg1, T(0.0), user_policy), user_defined_error);
+ BOOST_CHECK_THROW(boost::math::policy::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error);
+ BOOST_CHECK_THROW(boost::math::policy::raise_underflow_error<T>(func, msg2, user_policy), user_defined_error);
+ BOOST_CHECK_THROW(boost::math::policy::raise_denorm_error<T>(func, msg2, T(0), user_policy), user_defined_error);
+ BOOST_CHECK_THROW(boost::math::policy::raise_evaluation_error(func, msg1, T(0.0), user_policy), user_defined_error);
 
-} // template <class FPT>void test_error(FPT)
+}
 
 int test_main(int, char* [])
 {
@@ -92,115 +126,8 @@
         test_error(0.0F); // Test float.
         test_error(0.0); // Test double.
         test_error(0.0L); // Test long double.
- test_error(real_concept(0.0L)); // Test concepts.
+ test_error(boost::math::concepts::real_concept(0.0L)); // Test concepts.
         return 0;
 } // int test_main(int, char* [])
 
-/*
-
-Output:
-
-
------- Rebuild All started: Project: test_error_handling, Configuration: Release Win32 ------
-Deleting intermediate and output files for project 'test_error_handling', configuration 'Release|Win32'
-Compiling...
-test_error_handling.cpp
-Linking...
-Generating code
-Finished generating code
-Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\release\test_error_handling.exe"
-Running 1 test case...
-Current function is void __cdecl test_error<float>(float)
-Message from thrown exception was:
- Error in function void __cdecl test_error<float>(float): Domain Error on value 3.12456799
-Message from thrown exception was:
- Error in function void __cdecl test_error<float>(float): Out of range argument 3.12456799 in test invocation
-Message from thrown exception was:
- Error in function void __cdecl test_error<float>(float): Internal logic error, computed value was 3.12456799
-Message from thrown exception was:
- Error in function void __cdecl test_error<float>(float): Internal error, computed result was 3.12456799, but should be in the range [0,1]
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::chisqr_imp<double>(double,double): degrees of freedom argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): chisqr argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): degrees of freedom argument is 0, but must be > 0 !
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos6>(double,const struct boost::math::lanczos::lanczos6 &): Evaluation of tgamma at a negative integer 0.
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos6>(double,const struct boost::math::lanczos::lanczos6 &): Evaluation of tgamma at a negative integer -10.
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos6>(double,const struct boost::math::lanczos::lanczos6 &): Evaluation of tgamma at a negative integer -10123458117632.
-Current function is void __cdecl test_error<double>(double)
-Message from thrown exception was:
- Error in function void __cdecl test_error<double>(double): Domain Error on value 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<double>(double): Out of range argument 3.1245678901234566 in test invocation
-Message from thrown exception was:
- Error in function void __cdecl test_error<double>(double): Internal logic error, computed value was 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<double>(double): Internal error, computed result was 3.1245678901234566, but should be in the range [0,1]
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::chisqr_imp<double>(double,double): degrees of freedom argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::chisqr_imp<double>(double,double): chisqr argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::chisqr_imp<double>(double,double): degrees of freedom argument is 0, but must be > 0 !
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos13m53>(double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer 0.
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos13m53>(double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer -10.
-Message from thrown exception was:
- Error in function double __cdecl boost::math::detail::gamma_imp<double,struct boost::math::lanczos::lanczos13m53>(double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer -10123457772243.
-Current function is void __cdecl test_error<long double>(long double)
-Message from thrown exception was:
- Error in function void __cdecl test_error<long double>(long double): Domain Error on value 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<long double>(long double): Out of range argument 3.1245678901234566 in test invocation
-Message from thrown exception was:
- Error in function void __cdecl test_error<long double>(long double): Internal logic error, computed value was 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<long double>(long double): Internal error, computed result was 3.1245678901234566, but should be in the range [0,1]
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::chisqr_imp<long double>(long double,long double): degrees of freedom argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::chisqr_imp<long double>(long double,long double): chisqr argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::chisqr_imp<long double>(long double,long double): degrees of freedom argument is 0, but must be > 0 !
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::gamma_imp<long double,struct boost::math::lanczos::lanczos13m53>(long double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer 0.
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::gamma_imp<long double,struct boost::math::lanczos::lanczos13m53>(long double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer -10.
-Message from thrown exception was:
- Error in function long double __cdecl boost::math::detail::gamma_imp<long double,struct boost::math::lanczos::lanczos13m53>(long double,const struct boost::math::lanczos::lanczos13m53 &): Evaluation of tgamma at a negative integer -10123457772243.
-Current function is void __cdecl test_error<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept)
-Message from thrown exception was:
- Error in function void __cdecl test_error<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept): Domain Error on value 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept): Out of range argument 3.1245678901234566 in test invocation
-Message from thrown exception was:
- Error in function void __cdecl test_error<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept): Internal logic error, computed value was 3.1245678901234566
-Message from thrown exception was:
- Error in function void __cdecl test_error<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept): Internal error, computed result was 3.1245678901234566, but should be in the range [0,1]
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::chisqr_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,class boost::math::concepts::real_concept): degrees of freedom argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::chisqr_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,class boost::math::concepts::real_concept): chisqr argument is -1, but must be > 0 !
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::chisqr_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,class boost::math::concepts::real_concept): degrees of freedom argument is 0, but must be > 0 !
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::gamma_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,const struct boost::math::lanczos::undefined_lanczos &): Evaluation of tgamma at a negative integer 0.
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::gamma_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,const struct boost::math::lanczos::undefined_lanczos &): Evaluation of tgamma at a negative integer -10.
-Message from thrown exception was:
- Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::gamma_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,const struct boost::math::lanczos::undefined_lanczos &): Evaluation of tgamma at a negative integer -10123457772243.
-*** No errors detected
-Build Time 0:11
-Build log was saved at "file://i:\boost-06-05-03-1300\libs\math\test\Math_test\test_error_handling\Release\BuildLog.htm"
-test_error_handling - 0 error(s), 0 warning(s)
-========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
-
-
-
-*/
 

Modified: sandbox/math_toolkit/libs/math/test/test_factorials.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_factorials.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_factorials.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -9,6 +9,10 @@
 # pragma warning(disable: 4996) // 'std::char_traits<char>::copy' was declared deprecated.
 # pragma warning(disable: 4245) // int/unsigned int conversion
 #endif
+//
+// Return infinities not exceptions:
+//
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
 
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
@@ -206,7 +210,7 @@
       ::boost::math::falling_factorial(static_cast<T>(30.75), 30),
       static_cast<T>(naive_falling_factorial(30.75L, 30)),
       tolerance * 3);
- if(boost::math::tools::digits<T>() > 50)
+ if(boost::math::policy::digits<T, boost::math::policy::policy<> >() > 50)
    {
       BOOST_CHECK_CLOSE(
          ::boost::math::falling_factorial(static_cast<T>(-30.75L), 30),

Modified: sandbox/math_toolkit/libs/math/test/test_gamma.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_gamma.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_gamma.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,8 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
+
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
@@ -12,8 +14,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_gamma_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -50,7 +54,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -267,6 +271,7 @@
 template <class T>
 void do_test_gamma(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -317,11 +322,13 @@
 #endif
 
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
 void do_test_gammap1m1(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -342,6 +349,7 @@
       boost::lambda::ret<value_type>(boost::lambda::_1[1]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma1pm1", test_name);
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
@@ -435,8 +443,10 @@
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_gamma(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_gamma_dist.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_gamma_dist.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_gamma_dist.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -176,7 +176,7 @@
       tolerance);
 
 
- RealType tol2 = boost::math::tools::epsilon<RealType>() * 5;
+ RealType tol2 = boost::math::tools::epsilon<RealType>() * 5 * 100; // 5 eps as a persentage
     gamma_distribution<RealType> dist(8, 3);
     RealType x = static_cast<RealType>(0.125);
     using namespace std; // ADL of std names.

Modified: sandbox/math_toolkit/libs/math/test/test_hermite.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_hermite.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_hermite.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -47,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_ibeta.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ibeta.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ibeta.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,8 +12,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_beta_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -50,7 +52,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -230,6 +232,7 @@
 template <class T>
 void do_test_beta(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -296,6 +299,7 @@
    }
 #endif
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
@@ -482,16 +486,20 @@
    test_spots(0.0);
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_spots(0.0L);
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_spots(boost::math::concepts::real_concept(0.1));
 #endif
+#endif
 
    test_beta(0.1F, "float");
    test_beta(0.1, "double");
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_beta(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_ibeta_inv.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ibeta_inv.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ibeta_inv.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -61,7 +61,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -164,8 +164,8 @@
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
- value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::tools::digits<value_type>()/2)) * 100;
- if(boost::math::tools::digits<value_type>() < 50)
+ value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::policy::digits<value_type, boost::math::policy::policy<> >()/2)) * 100;
+ if(boost::math::policy::digits<value_type, boost::math::policy::policy<> >() < 50)
       precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated
 
    for(unsigned i = 0; i < data.size(); ++i)

Modified: sandbox/math_toolkit/libs/math/test/test_ibeta_inv_ab.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_ibeta_inv_ab.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_ibeta_inv_ab.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -54,7 +54,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -115,8 +115,8 @@
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
- value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::tools::digits<value_type>()/2)) * 100;
- if(boost::math::tools::digits<value_type>() < 50)
+ value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::policy::digits<value_type, boost::math::policy::policy<> >()/2)) * 100;
+ if(boost::math::policy::digits<value_type, boost::math::policy::policy<> >() < 50)
       precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated
 
    for(unsigned i = 0; i < data.size(); ++i)
@@ -260,6 +260,8 @@
 int test_main(int, char* [])
 {
    expected_results();
+ boost::math::ibetac_invb(15.3268413543701171875f, 0.3082362115383148193359375f, 0.913384497165679931640625f);
+ boost::math::ibetac(15.3268413543701171875f, 21.432123240471673235001418f, 0.3082362115383148193359375f);
 #ifdef TEST_GSL
    gsl_set_error_handler_off();
 #endif

Modified: sandbox/math_toolkit/libs/math/test/test_igamma.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_igamma.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_igamma.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -3,6 +3,8 @@
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
+
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/math/special_functions/gamma.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
@@ -12,8 +14,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_gamma_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -50,7 +54,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -228,6 +232,7 @@
 template <class T>
 void do_test_gamma_2(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -308,6 +313,7 @@
    }
 #endif
    std::cout << std::endl;
+#endif
 }
 
 template <class T>
@@ -390,16 +396,20 @@
    test_spots(0.0);
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_spots(0.0L);
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_spots(boost::math::concepts::real_concept(0.1));
 #endif
+#endif
 
    test_gamma(0.1F, "float");
    test_gamma(0.1, "double");
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_gamma(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_igamma_inv.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_igamma_inv.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_igamma_inv.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,8 +12,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "test_gamma_hooks.hpp"
 #include "handle_test_result.hpp"
@@ -53,7 +55,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -202,8 +204,8 @@
    // and also demonstrates that you can't in general round-trip these functions.
    // It is however a useful sanity check.
    //
- value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::tools::digits<value_type>()/2)) * 100;
- if(boost::math::tools::digits<value_type>() < 50)
+ value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::policy::digits<value_type, boost::math::policy::policy<> >()/2)) * 100;
+ if(boost::math::policy::digits<value_type, boost::math::policy::policy<> >() < 50)
       precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated to float
 
    for(unsigned i = 0; i < data.size(); ++i)
@@ -254,6 +256,7 @@
 template <class T>
 void do_test_gamma_inv(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -284,6 +287,7 @@
       bind(funcp, ret<value_type>(_1[0]), ret<value_type>(_1[1])),
       ret<value_type>(_1[3]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::gamma_q_inv", test_name);
+#endif
 }
 
 template <class T>
@@ -365,16 +369,20 @@
    test_spots(0.0, "double");
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_spots(0.0L, "long double");
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 
    test_gamma(0.1F, "float");
    test_gamma(0.1, "double");
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_gamma(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_igamma_inva.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_igamma_inva.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_igamma_inva.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -12,8 +12,10 @@
 #include <boost/math/constants/constants.hpp>
 #include <boost/type_traits/is_floating_point.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "handle_test_result.hpp"
 
@@ -49,7 +51,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -128,8 +130,8 @@
    // and also demonstrates that you can't in general round-trip these functions.
    // It is however a useful sanity check.
    //
- value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::tools::digits<value_type>()/2)) * 100;
- if(boost::math::tools::digits<value_type>() < 50)
+ value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::policy::digits<value_type, boost::math::policy::policy<> >()/2)) * 100;
+ if(boost::math::policy::digits<value_type, boost::math::policy::policy<> >() < 50)
       precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated to float
 
    for(unsigned i = 0; i < data.size(); ++i)
@@ -180,6 +182,7 @@
 template <class T>
 void do_test_gamma_inva(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -210,6 +213,7 @@
       bind(funcp, ret<value_type>(_1[0]), ret<value_type>(_1[1])),
       ret<value_type>(_1[3]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::gamma_q_inva", test_name);
+#endif
 }
 
 template <class T>
@@ -250,8 +254,10 @@
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_gamma(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/test/test_laguerre.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_laguerre.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_laguerre.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -47,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_legendre.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_legendre.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_legendre.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -47,7 +47,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_negative_binomial.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_negative_binomial.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_negative_binomial.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -16,6 +16,8 @@
 // Nor are these defined - several tests underflow by design.
 //#define BOOST_MATH_THROW_ON_UNDERFLOW_ERROR
 //#define BOOST_MATH_THROW_ON_DENORM_ERROR
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
+#define BOOST_MATH_DISCRETE_QUANTILE_POLICY real
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // conditional expression is constant.
@@ -623,17 +625,17 @@
    } // test for infinity using std::numeric_limits<>::infinity()
   else
   { // real_concept case, so check it throws rather than returning infinity.
- BOOST_CHECK_THROW(
+ BOOST_CHECK_EQUAL(
     quantile( // At P == 1 so k failures should be infinite.
     negative_binomial_distribution<RealType>(static_cast<RealType>(8), static_cast<RealType>(0.25)),
     static_cast<RealType>(1)),
- std::overflow_error );
+ boost::math::tools::max_value<RealType>() );
 
- BOOST_CHECK_THROW(
+ BOOST_CHECK_EQUAL(
     quantile(complement( // Q zero 1 so P == 1 < cdf(0) so should be exactly infinity.
     negative_binomial_distribution<RealType>(static_cast<RealType>(8), static_cast<RealType>(0.25)),
     static_cast<RealType>(0))),
- std::overflow_error);
+ boost::math::tools::max_value<RealType>());
   }
   BOOST_CHECK( // Should work for built-in and real_concept.
   quantile(complement( // Q very near to 1 so P nearly 1 < so should be large > 384.
@@ -719,6 +721,71 @@
   );
   // End of check throwing 'duff' out-of-domain values.
 
+#define T RealType
+#include "negative_binomial_quantile.ipp"
+
+ for(unsigned i = 0; i < negative_binomial_quantile_data.size(); ++i)
+ {
+ using namespace boost::math::policy;
+ typedef policy<discrete_quantile<boost::math::policy::real> > P1;
+ typedef policy<discrete_quantile<integer_below> > P2;
+ typedef policy<discrete_quantile<integer_above> > P3;
+ typedef policy<discrete_quantile<integer_outside> > P4;
+ typedef policy<discrete_quantile<integer_inside> > P5;
+ typedef policy<discrete_quantile<integer_nearest> > P6;
+ RealType tol = boost::math::tools::epsilon<RealType>() * 700;
+ if(!boost::is_floating_point<RealType>::value)
+ tol *= 10; // no lanczos approximation implies less accuracy
+ //
+ // Check full real value first:
+ //
+ negative_binomial_distribution<RealType, P1> p1(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ RealType x = quantile(p1, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_CLOSE_FRACTION(x, negative_binomial_quantile_data[i][3], tol);
+ x = quantile(complement(p1, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_CLOSE_FRACTION(x, negative_binomial_quantile_data[i][4], tol);
+ //
+ // Now with round down to integer:
+ //
+ negative_binomial_distribution<RealType, P2> p2(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ x = quantile(p2, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, floor(negative_binomial_quantile_data[i][3]));
+ x = quantile(complement(p2, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, floor(negative_binomial_quantile_data[i][4]));
+ //
+ // Now with round up to integer:
+ //
+ negative_binomial_distribution<RealType, P3> p3(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ x = quantile(p3, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, ceil(negative_binomial_quantile_data[i][3]));
+ x = quantile(complement(p3, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, ceil(negative_binomial_quantile_data[i][4]));
+ //
+ // Now with round to integer "outside":
+ //
+ negative_binomial_distribution<RealType, P4> p4(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ x = quantile(p4, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, negative_binomial_quantile_data[i][2] < 0.5f ? floor(negative_binomial_quantile_data[i][3]) : ceil(negative_binomial_quantile_data[i][3]));
+ x = quantile(complement(p4, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, negative_binomial_quantile_data[i][2] < 0.5f ? ceil(negative_binomial_quantile_data[i][4]) : floor(negative_binomial_quantile_data[i][4]));
+ //
+ // Now with round to integer "inside":
+ //
+ negative_binomial_distribution<RealType, P5> p5(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ x = quantile(p5, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, negative_binomial_quantile_data[i][2] < 0.5f ? ceil(negative_binomial_quantile_data[i][3]) : floor(negative_binomial_quantile_data[i][3]));
+ x = quantile(complement(p5, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, negative_binomial_quantile_data[i][2] < 0.5f ? floor(negative_binomial_quantile_data[i][4]) : ceil(negative_binomial_quantile_data[i][4]));
+ //
+ // Now with round to nearest integer:
+ //
+ negative_binomial_distribution<RealType, P6> p6(negative_binomial_quantile_data[i][0], negative_binomial_quantile_data[i][1]);
+ x = quantile(p6, negative_binomial_quantile_data[i][2]);
+ BOOST_CHECK_EQUAL(x, floor(negative_binomial_quantile_data[i][3] + 0.5f));
+ x = quantile(complement(p6, negative_binomial_quantile_data[i][2]));
+ BOOST_CHECK_EQUAL(x, floor(negative_binomial_quantile_data[i][4] + 0.5f));
+ }
+
   return;
 } // template <class RealType> void test_spots(RealType) // Any floating-point type RealType.
 

Modified: sandbox/math_toolkit/libs/math/test/test_poisson.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_poisson.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_poisson.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -11,6 +11,7 @@
 
 #define BOOST_MATH_THROW_ON_DOMAIN_ERROR
 #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR
+#define BOOST_MATH_DISCRETE_QUANTILE_POLICY real
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // conditional expression is constant.
@@ -416,6 +417,73 @@
            static_cast<RealType>(0.9999))), // complement, so 1-probability < cdf(0)
            static_cast<RealType>(0)); // Expect k = 0 events exactly.
 
+ //
+ // Test quantile policies against test data:
+ //
+#define T RealType
+#include "poisson_quantile.ipp"
+
+ for(unsigned i = 0; i < poisson_quantile_data.size(); ++i)
+ {
+ using namespace boost::math::policy;
+ typedef policy<discrete_quantile<real> > P1;
+ typedef policy<discrete_quantile<integer_below> > P2;
+ typedef policy<discrete_quantile<integer_above> > P3;
+ typedef policy<discrete_quantile<integer_outside> > P4;
+ typedef policy<discrete_quantile<integer_inside> > P5;
+ typedef policy<discrete_quantile<integer_nearest> > P6;
+ RealType tol = boost::math::tools::epsilon<RealType>() * 20;
+ if(!boost::is_floating_point<RealType>::value)
+ tol *= 7;
+ //
+ // Check full real value first:
+ //
+ poisson_distribution<RealType, P1> p1(poisson_quantile_data[i][0]);
+ RealType x = quantile(p1, poisson_quantile_data[i][1]);
+ BOOST_CHECK_CLOSE_FRACTION(x, poisson_quantile_data[i][2], tol);
+ x = quantile(complement(p1, poisson_quantile_data[i][1]));
+ BOOST_CHECK_CLOSE_FRACTION(x, poisson_quantile_data[i][3], tol);
+ //
+ // Now with round down to integer:
+ //
+ poisson_distribution<RealType, P2> p2(poisson_quantile_data[i][0]);
+ x = quantile(p2, poisson_quantile_data[i][1]);
+ BOOST_CHECK_EQUAL(x, floor(poisson_quantile_data[i][2]));
+ x = quantile(complement(p2, poisson_quantile_data[i][1]));
+ BOOST_CHECK_EQUAL(x, floor(poisson_quantile_data[i][3]));
+ //
+ // Now with round up to integer:
+ //
+ poisson_distribution<RealType, P3> p3(poisson_quantile_data[i][0]);
+ x = quantile(p3, poisson_quantile_data[i][1]);
+ BOOST_CHECK_EQUAL(x, ceil(poisson_quantile_data[i][2]));
+ x = quantile(complement(p3, poisson_quantile_data[i][1]));
+ BOOST_CHECK_EQUAL(x, ceil(poisson_quantile_data[i][3]));
+ //
+ // Now with round to integer "outside":
+ //
+ poisson_distribution<RealType, P4> p4(poisson_quantile_data[i][0]);
+ x = quantile(p4, poisson_quantile_data[i][1]);
+ BOOST_CHECK_EQUAL(x, poisson_quantile_data[i][1] < 0.5f ? floor(poisson_quantile_data[i][2]) : ceil(poisson_quantile_data[i][2]));
+ x = quantile(complement(p4, poisson_quantile_data[i][1]));
+ BOOST_CHECK_EQUAL(x, poisson_quantile_data[i][1] < 0.5f ? ceil(poisson_quantile_data[i][3]) : floor(poisson_quantile_data[i][3]));
+ //
+ // Now with round to integer "inside":
+ //
+ poisson_distribution<RealType, P5> p5(poisson_quantile_data[i][0]);
+ x = quantile(p5, poisson_quantile_data[i][1]);
+ BOOST_CHECK_EQUAL(x, poisson_quantile_data[i][1] < 0.5f ? ceil(poisson_quantile_data[i][2]) : floor(poisson_quantile_data[i][2]));
+ x = quantile(complement(p5, poisson_quantile_data[i][1]));
+ BOOST_CHECK_EQUAL(x, poisson_quantile_data[i][1] < 0.5f ? floor(poisson_quantile_data[i][3]) : ceil(poisson_quantile_data[i][3]));
+ //
+ // Now with round to nearest integer:
+ //
+ poisson_distribution<RealType, P6> p6(poisson_quantile_data[i][0]);
+ x = quantile(p6, poisson_quantile_data[i][1]);
+ BOOST_CHECK_EQUAL(x, floor(poisson_quantile_data[i][2] + 0.5f));
+ x = quantile(complement(p6, poisson_quantile_data[i][1]));
+ BOOST_CHECK_EQUAL(x, floor(poisson_quantile_data[i][3] + 0.5f));
+ }
 
 } // template <class RealType>void test_spots(RealType)
 

Added: sandbox/math_toolkit/libs/math/test/test_policy.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/test/test_policy.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -0,0 +1,229 @@
+
+// Copyright John Maddock 2007.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/math/policy/policy.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/test/included/test_exec_monitor.hpp> // for test_main
+
+template <class P1, class P2>
+bool check_same(const P1&, const P2&)
+{
+ if(!boost::is_same<P1, P2>::value)
+ {
+ std::cout << "P1 = " << typeid(P1).name() << std::endl;
+ std::cout << "P2 = " << typeid(P2).name() << std::endl;
+ }
+ return boost::is_same<P1, P2>::value;
+}
+
+
+int test_main(int, char* [])
+{
+ using namespace boost::math::policy;
+ using namespace boost;
+ BOOST_CHECK(is_domain_error<domain_error<ignore_error> >::value);
+ BOOST_CHECK(0 == is_domain_error<pole_error<ignore_error> >::value);
+ BOOST_CHECK(is_pole_error<pole_error<ignore_error> >::value);
+ BOOST_CHECK(0 == is_pole_error<domain_error<ignore_error> >::value);
+ BOOST_CHECK(is_digits10<digits10<ignore_error> >::value);
+ BOOST_CHECK(0 == is_digits10<digits2<ignore_error> >::value);
+
+ BOOST_CHECK((is_same<policy<>::domain_error_type, domain_error<BOOST_MATH_DOMAIN_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<>::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::denorm_error_type, denorm_error<BOOST_MATH_DENORM_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::pole_error_type, pole_error<user_error> >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::denorm_error_type, denorm_error<BOOST_MATH_DENORM_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<pole_error<user_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::overflow_error_type, overflow_error<errno_on_error> >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::denorm_error_type, denorm_error<BOOST_MATH_DENORM_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<overflow_error<errno_on_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::underflow_error_type, underflow_error<errno_on_error> >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::denorm_error_type, denorm_error<BOOST_MATH_DENORM_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<underflow_error<errno_on_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::denorm_error_type, denorm_error<errno_on_error> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<errno_on_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::denorm_error_type, policy<>::denorm_error_type >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::evaluation_error_type, evaluation_error<errno_on_error> >::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<evaluation_error<errno_on_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<digits2<20> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::denorm_error_type, policy<>::denorm_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::evaluation_error_type, policy<>::evaluation_error_type >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::precision_type, digits2<20> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<digits2<20> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<promote_float<false> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::denorm_error_type, policy<>::denorm_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::evaluation_error_type, policy<>::evaluation_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::precision_type, policy<>::precision_type >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::promote_float_type, promote_float<false> >::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<promote_float<false> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<promote_double<false> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::denorm_error_type, policy<>::denorm_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::evaluation_error_type, policy<>::evaluation_error_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::precision_type, policy<>::precision_type >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::promote_double_type, promote_double<false> >::value));
+ BOOST_CHECK((is_same<policy<promote_double<false> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::domain_error_type, policy<>::domain_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::pole_error_type, policy<>::pole_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::overflow_error_type, policy<>::overflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::underflow_error_type, policy<>::underflow_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::denorm_error_type, policy<>::denorm_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::evaluation_error_type, policy<>::evaluation_error_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::precision_type, policy<>::precision_type >::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<discrete_quantile<integer_above> >::discrete_quantile_type, discrete_quantile<integer_above> >::value));
+
+ //
+ // Now try again with 2 policies:
+ //
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::overflow_error_type, overflow_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::denorm_error_type, denorm_error<BOOST_MATH_DENORM_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<domain_error<ignore_error>, overflow_error<ignore_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::denorm_error_type, denorm_error<throw_on_error> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::precision_type, policy<>::precision_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::promote_float_type, policy<>::promote_float_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<denorm_error<throw_on_error>, domain_error<ignore_error> >::discrete_quantile_type, policy<>::discrete_quantile_type>::value));
+
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::denorm_error_type, denorm_error<throw_on_error> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::precision_type, digits2<20> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::promote_float_type, promote_float<false> >::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::discrete_quantile_type, discrete_quantile<integer_below> >::value));
+
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::denorm_error_type, denorm_error<throw_on_error> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::precision_type, digits2<20> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::promote_float_type, promote_float<false> >::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<normalise<policy<digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> > >::type::discrete_quantile_type, discrete_quantile<integer_below> >::value));
+
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::domain_error_type, domain_error<ignore_error> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::pole_error_type, pole_error<BOOST_MATH_POLE_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::overflow_error_type, overflow_error<BOOST_MATH_OVERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::underflow_error_type, underflow_error<BOOST_MATH_UNDERFLOW_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::denorm_error_type, denorm_error<throw_on_error> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::evaluation_error_type, evaluation_error<BOOST_MATH_EVALUATION_ERROR_POLICY> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::precision_type, digits2<20> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::promote_float_type, promote_float<false> >::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::promote_double_type, policy<>::promote_double_type>::value));
+ BOOST_CHECK((is_same<normalise<policy<>, digits2<20>, promote_float<false>, discrete_quantile<integer_below>, denorm_error<throw_on_error>, domain_error<ignore_error> >::type::discrete_quantile_type, discrete_quantile<integer_below> >::value));
+
+ BOOST_CHECK(check_same(make_policy(), policy<>()));
+ BOOST_CHECK(check_same(make_policy(denorm_error<ignore_error>()), normalise<policy<denorm_error<ignore_error> > >::type()));
+ BOOST_CHECK(check_same(make_policy(digits2<20>()), normalise<policy<digits2<20> > >::type()));
+ BOOST_CHECK(check_same(make_policy(promote_float<false>()), normalise<policy<promote_float<false> > >::type()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>()), normalise<policy<domain_error<ignore_error> > >::type()));
+ BOOST_CHECK(check_same(make_policy(pole_error<ignore_error>()), normalise<policy<pole_error<ignore_error> > >::type()));
+
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>()), policy<domain_error<ignore_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>()), policy<domain_error<ignore_error>, pole_error<ignore_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), digits2<10>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, digits2<10> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), digits10<5>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, digits2<19> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), digits2<10>(), promote_float<false>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, digits2<10>, promote_float<false> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), digits2<10>(), promote_float<false>(), promote_double<false>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, digits2<10>, promote_float<false>, promote_double<false> >()));
+ BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), digits2<10>(), promote_float<false>(), promote_double<false>(), discrete_quantile<integer_below>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, digits2<10>, promote_float<false>, promote_double<false>, discrete_quantile<integer_below> >()));
+
+ return 0;
+} // int test_main(int, char* [])
+
+

Modified: sandbox/math_toolkit/libs/math/test/test_rational_instances/test_rational.hpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_rational_instances/test_rational.hpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_rational_instances/test_rational.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -6,6 +6,7 @@
 #include <boost/test/test_exec_monitor.hpp>
 #include <boost/array.hpp>
 #include <boost/math/tools/rational.hpp>
+#include <boost/math/tools/precision.hpp>
 
 template <class T, class U>
 void do_test_spots1(T, U)

Modified: sandbox/math_toolkit/libs/math/test/test_rationals.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_rationals.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_rationals.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -8,6 +8,7 @@
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/array.hpp>
 #include <boost/math/tools/rational.hpp>
+#include <iostream>
 
 template <class T, class U>
 void do_test_spots(T, U);

Modified: sandbox/math_toolkit/libs/math/test/test_remez.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_remez.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_remez.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -100,6 +100,10 @@
       std::cout << approx1.error_term() << " " << approx1.max_error() << " " << approx1.max_change() << std::endl;
    }
    std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
+#if 0
+ //
+ // This one causes UBLAS to fail on some systems, so disabled for now.
+ //
    std::cout << "Testing expm1 approximation, pinned to origin, relative error, 3+3 term rational\n";
    boost::math::tools::remez_minimax<double> approx2(f, 3, 3, -1, 1, true, true);
    std::cout << "Interpolation Error: " << approx1.max_error() << std::endl;
@@ -109,7 +113,7 @@
       std::cout << approx2.error_term() << " " << approx2.max_error() << " " << approx2.max_change() << std::endl;
    }
    std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
-
+#endif
    f = std::exp;
    std::cout << "Testing exp approximation, not pinned to origin, abolute error, 3+3 term rational\n";
    boost::math::tools::remez_minimax<double> approx3(f, 3, 3, -1, 1, false, false);

Modified: sandbox/math_toolkit/libs/math/test/test_roots.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_roots.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_roots.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -16,7 +16,7 @@
 // we could ever wish for!!!
 //
 
-template <class T, class L>
+template <class T, class Policy>
 struct ibeta_roots_1 // for first order algorithms
 {
    ibeta_roots_1(T _a, T _b, T t, bool inv = false)
@@ -24,14 +24,14 @@
 
    T operator()(const T& x)
    {
- return boost::math::detail::ibeta_imp(a, b, x, L(), invert, true) - target;
+ return boost::math::detail::ibeta_imp(a, b, x, Policy(), invert, true) - target;
    }
 private:
    T a, b, target;
    bool invert;
 };
 
-template <class T, class L>
+template <class T, class Policy>
 struct ibeta_roots_2 // for second order algorithms
 {
    ibeta_roots_2(T _a, T _b, T t, bool inv = false)
@@ -39,10 +39,11 @@
 
    std::tr1::tuple<T, T> operator()(const T& x)
    {
- T f = boost::math::detail::ibeta_imp(a, b, x, L(), invert, true) - target;
+ typedef typename boost::math::lanczos::lanczos<T, Policy>::type L;
+ T f = boost::math::detail::ibeta_imp(a, b, x, Policy(), invert, true) - target;
       T f1 = invert ?
- -boost::math::detail::ibeta_power_terms(b, a, 1 - x, x, L(), true)
- : boost::math::detail::ibeta_power_terms(a, b, x, 1 - x, L(), true);
+ -boost::math::detail::ibeta_power_terms(b, a, 1 - x, x, L(), true, Policy())
+ : boost::math::detail::ibeta_power_terms(a, b, x, 1 - x, L(), true, Policy());
       T y = 1 - x;
       if(y == 0)
          y = boost::math::tools::min_value<T>() * 8;
@@ -59,7 +60,7 @@
    bool invert;
 };
 
-template <class T, class L>
+template <class T, class Policy>
 struct ibeta_roots_3 // for third order algorithms
 {
    ibeta_roots_3(T _a, T _b, T t, bool inv = false)
@@ -67,10 +68,11 @@
 
    std::tr1::tuple<T, T, T> operator()(const T& x)
    {
- T f = boost::math::detail::ibeta_imp(a, b, x, L(), invert, true) - target;
+ typedef typename boost::math::lanczos::lanczos<T, Policy>::type L;
+ T f = boost::math::detail::ibeta_imp(a, b, x, Policy(), invert, true) - target;
       T f1 = invert ?
- -boost::math::detail::ibeta_power_terms(b, a, 1 - x, x, L(), true)
- : boost::math::detail::ibeta_power_terms(a, b, x, 1 - x, L(), true);
+ -boost::math::detail::ibeta_power_terms(b, a, 1 - x, x, L(), true, Policy())
+ : boost::math::detail::ibeta_power_terms(a, b, x, 1 - x, L(), true, Policy());
       T y = 1 - x;
       if(y == 0)
          y = boost::math::tools::min_value<T>() * 8;
@@ -92,7 +94,7 @@
 
 double inverse_ibeta_bisect(double a, double b, double z)
 {
- typedef boost::math::lanczos::lanczos13m53 L;
+ typedef boost::math::policy::policy<> pol;
    bool invert = false;
    int bits = std::numeric_limits<double>::digits;
 
@@ -119,12 +121,11 @@
    double min = 0;
    double max = 1;
    boost::math::tools::eps_tolerance<double> tol(precision);
- return boost::math::tools::bisect(ibeta_roots_1<double, L>(a, b, z, invert), min, max, tol).first;
+ return boost::math::tools::bisect(ibeta_roots_1<double, pol>(a, b, z, invert), min, max, tol).first;
 }
 
 double inverse_ibeta_newton(double a, double b, double z)
 {
- typedef boost::math::lanczos::lanczos13m53 L;
    double guess = 0.5;
    bool invert = false;
    int bits = std::numeric_limits<double>::digits;
@@ -151,12 +152,11 @@
 
    double min = 0;
    double max = 1;
- return boost::math::tools::newton_raphson_iterate(ibeta_roots_2<double, L>(a, b, z, invert), guess, min, max, precision);
+ return boost::math::tools::newton_raphson_iterate(ibeta_roots_2<double, boost::math::policy::policy<> >(a, b, z, invert), guess, min, max, precision);
 }
 
 double inverse_ibeta_halley(double a, double b, double z)
 {
- typedef boost::math::lanczos::lanczos13m53 L;
    double guess = 0.5;
    bool invert = false;
    int bits = std::numeric_limits<double>::digits;
@@ -183,12 +183,11 @@
 
    double min = 0;
    double max = 1;
- return boost::math::tools::halley_iterate(ibeta_roots_3<double, L>(a, b, z, invert), guess, min, max, precision);
+ return boost::math::tools::halley_iterate(ibeta_roots_3<double, boost::math::policy::policy<> >(a, b, z, invert), guess, min, max, precision);
 }
 
 double inverse_ibeta_schroeder(double a, double b, double z)
 {
- typedef boost::math::lanczos::lanczos13m53 L;
    double guess = 0.5;
    bool invert = false;
    int bits = std::numeric_limits<double>::digits;
@@ -215,7 +214,7 @@
 
    double min = 0;
    double max = 1;
- return boost::math::tools::schroeder_iterate(ibeta_roots_3<double, L>(a, b, z, invert), guess, min, max, precision);
+ return boost::math::tools::schroeder_iterate(ibeta_roots_3<double, boost::math::policy::policy<> >(a, b, z, invert), guess, min, max, precision);
 }
 
 
@@ -226,8 +225,8 @@
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
- value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::tools::digits<value_type>()/2)) * 100;
- if(boost::math::tools::digits<value_type>() < 50)
+ value_type precision = static_cast<value_type>(ldexp(1.0, 1-boost::math::policy::digits<value_type, boost::math::policy::policy<> >()/2)) * 100;
+ if(boost::math::policy::digits<value_type, boost::math::policy::policy<> >() < 50)
       precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated
 
    for(unsigned i = 0; i < data.size(); ++i)

Modified: sandbox/math_toolkit/libs/math/test/test_spherical_harmonic.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_spherical_harmonic.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_spherical_harmonic.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -46,7 +46,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }

Modified: sandbox/math_toolkit/libs/math/test/test_tgamma_ratio.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_tgamma_ratio.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_tgamma_ratio.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -2,6 +2,9 @@
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
+
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
@@ -9,8 +12,10 @@
 #include <boost/math/tools/stats.hpp>
 #include <boost/math/tools/test.hpp>
 #include <boost/array.hpp>
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
+#endif
 
 #include "handle_test_result.hpp"
 
@@ -43,7 +48,7 @@
    //
    const char* largest_type;
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
- if(boost::math::tools::digits<double>() == boost::math::tools::digits<long double>())
+ if(boost::math::policy::digits<double, boost::math::policy::policy<> >() == boost::math::policy::digits<long double, boost::math::policy::policy<> >())
    {
       largest_type = "(long\\s+)?double";
    }
@@ -112,6 +117,7 @@
 template <class T>
 void do_test_tgamma_delta_ratio(const T& data, const char* type_name, const char* test_name)
 {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    typedef typename T::value_type row_type;
    typedef typename row_type::value_type value_type;
 
@@ -140,6 +146,7 @@
          -boost::lambda::ret<value_type>(boost::lambda::_1[1])),
       boost::lambda::ret<value_type>(boost::lambda::_1[3]));
    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma_delta_ratio(a -delta)", test_name);
+#endif
 }
 
 template <class T>
@@ -201,8 +208,10 @@
 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
    test_tgamma_ratio(0.1L, "long double");
 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    test_tgamma_ratio(boost::math::concepts::real_concept(0.1), "real_concept");
 #endif
+#endif
 #else
    std::cout << "<note>The long double tests have been disabled on this platform "
       "either because the long double overloads of the usual math functions are "

Modified: sandbox/math_toolkit/libs/math/tools/ibeta_data.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/tools/ibeta_data.cpp (original)
+++ sandbox/math_toolkit/libs/math/tools/ibeta_data.cpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -87,7 +87,7 @@
 T get_ibeta_fraction1(T a, T b, T x)
 {
    ibeta_fraction1_t<T> f(a, b, x);
- T fract = boost::math::tools::continued_fraction_a(f, boost::math::tools::digits<T>());
+ T fract = boost::math::tools::continued_fraction_a(f, boost::math::policy::digits<T, boost::math::policy<> >());
    T denom = (a * (fract + 1));
    T num = pow(x, a) * pow(1 - x, b);
    if(num == 0)

Modified: sandbox/math_toolkit/libs/math/tools/ntl_rr_lanczos.hpp
==============================================================================
--- sandbox/math_toolkit/libs/math/tools/ntl_rr_lanczos.hpp (original)
+++ sandbox/math_toolkit/libs/math/tools/ntl_rr_lanczos.hpp 2007-07-25 07:51:46 EDT (Wed, 25 Jul 2007)
@@ -881,18 +881,17 @@
 
 namespace boost{ namespace math{ namespace lanczos{
 
-template<>
-struct lanczos_traits<NTL::RR>
+template<class Policy>
+struct lanczos<NTL::RR, Policy>
 {
- typedef NTL::RR value_type;
 #ifdef L13
- typedef lanczos13UDT evaluation_type;
+ typedef lanczos13UDT type;
 #elif defined(L22)
- typedef lanczos22UDT evaluation_type;
+ typedef lanczos22UDT type;
 #elif defined(L31)
- typedef lanczos31UDT evaluation_type;
+ typedef lanczos31UDT type;
 #else
- typedef lanczos61UDT evaluation_type;
+ typedef lanczos61UDT type;
 #endif
 };
 


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