Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83168 - in trunk/boost/math/special_functions: . detail
From: e_float_at_[hidden]
Date: 2013-02-26 15:34:24


Author: christopher_kormanyos
Date: 2013-02-26 15:34:23 EST (Tue, 26 Feb 2013)
New Revision: 83168
URL: http://svn.boost.org/trac/boost/changeset/83168

Log:
Added exception handling to airy_ai_zero() and airy_bi_zero().
Text files modified:
   trunk/boost/math/special_functions/airy.hpp | 11 ++++-------
   trunk/boost/math/special_functions/detail/airy_ai_bi_zero.hpp | 26 ++++++++------------------
   2 files changed, 12 insertions(+), 25 deletions(-)

Modified: trunk/boost/math/special_functions/airy.hpp
==============================================================================
--- trunk/boost/math/special_functions/airy.hpp (original)
+++ trunk/boost/math/special_functions/airy.hpp 2013-02-26 15:34:23 EST (Tue, 26 Feb 2013)
@@ -159,9 +159,8 @@
    BOOST_MATH_STD_USING // ADL of std names, needed for log, sqrt.
 
    // Handle cases when the zero'th zero is requested.
- // Return NaN if NaN is available or return 0 if NaN is not available.
    if(m == 0U)
- return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : T(0));
+ return policies::raise_domain_error<T>(function, "The requested rank of the zero is %1%, but must be 1 or more !", m, pol);
 
    // Set up the initial guess for the upcoming root-finding.
    const T guess_root = boost::math::detail::airy_zero::airy_ai_zero_detail::initial_guess<T>(m);
@@ -186,7 +185,7 @@
    // Perform the root-finding using Newton-Raphson iteration from Boost.Math.
    const T am =
       boost::math::tools::newton_raphson_iterate(
- boost::math::detail::airy_zero::airy_ai_zero_detail::function_object<T, Policy>(pol),
+ boost::math::detail::airy_zero::airy_ai_zero_detail::function_object_ai_and_ai_prime<T, Policy>(pol),
          guess_root,
          T(guess_root - tolerance),
          T(guess_root + tolerance),
@@ -204,9 +203,8 @@
    BOOST_MATH_STD_USING // ADL of std names, needed for log, sqrt.
 
    // Handle cases when the zero'th zero is requested.
- // Return NaN if NaN is available or return 0 if NaN is not available.
    if(m == 0U)
- return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : T(0));
+ return policies::raise_domain_error<T>(function, "The requested rank of the zero is %1%, but must be 1 or more !", m, pol);
 
    // Set up the initial guess for the upcoming root-finding.
    const T guess_root = boost::math::detail::airy_zero::airy_bi_zero_detail::initial_guess<T>(m);
@@ -221,7 +219,6 @@
                                  / log(2.0F)));
 
    // Use a dynamic tolerance because the roots get closer the higher m gets.
- // Use a dynamic tolerance because the roots get closer the higher m gets.
    T tolerance;
 
    if (m <= 10U) { tolerance = T(0.3F); }
@@ -232,7 +229,7 @@
    // Perform the root-finding using Newton-Raphson iteration from Boost.Math.
    const T bm =
       boost::math::tools::newton_raphson_iterate(
- boost::math::detail::airy_zero::airy_bi_zero_detail::function_object<T, Policy>(pol),
+ boost::math::detail::airy_zero::airy_bi_zero_detail::function_object_bi_and_bi_prime<T, Policy>(pol),
          guess_root,
          T(guess_root - tolerance),
          T(guess_root + tolerance),

Modified: trunk/boost/math/special_functions/detail/airy_ai_bi_zero.hpp
==============================================================================
--- trunk/boost/math/special_functions/detail/airy_ai_bi_zero.hpp (original)
+++ trunk/boost/math/special_functions/detail/airy_ai_bi_zero.hpp 2013-02-26 15:34:23 EST (Tue, 26 Feb 2013)
@@ -58,15 +58,9 @@
         {
           T guess;
 
- if(m == 0U)
- {
- // Requesting an estimate of the zero'th root is an error.
- // Return zero.
- guess = T(0);
- }
-
           switch(m)
           {
+ case 0U: { guess = T(0); break; }
             case 1U: { guess = T(-2.33810741045976703849); break; }
             case 2U: { guess = T(-4.08794944413097061664); break; }
             case 3U: { guess = T(-5.52055982809555105913); break; }
@@ -89,10 +83,10 @@
         }
 
         template<class T, class Policy>
- class function_object
+ class function_object_ai_and_ai_prime
         {
         public:
- function_object(const Policy pol) : my_pol(pol) { }
+ function_object_ai_and_ai_prime(const Policy pol) : my_pol(pol) { }
 
           boost::math::tuple<T, T> operator()(const T& x) const
           {
@@ -104,6 +98,7 @@
 
         private:
           const Policy& my_pol;
+ const function_object_ai_and_ai_prime& operator=(const function_object_ai_and_ai_prime&);
         };
       } // namespace airy_ai_zero_detail
 
@@ -114,15 +109,9 @@
         {
           T guess;
 
- if(m == 0U)
- {
- // Requesting an estimate of the zero'th root is an error.
- // Return zero.
- guess = T(0);
- }
-
           switch(m)
           {
+ case 0U: { guess = T(0); break; }
             case 1U: { guess = T(-1.17371322270912792492); break; }
             case 2U: { guess = T(-3.27109330283635271568); break; }
             case 3U: { guess = T(-4.83073784166201593267); break; }
@@ -145,10 +134,10 @@
         }
 
         template<class T, class Policy>
- class function_object
+ class function_object_bi_and_bi_prime
         {
         public:
- function_object(const Policy pol) : my_pol(pol) { }
+ function_object_bi_and_bi_prime(const Policy pol) : my_pol(pol) { }
 
           boost::math::tuple<T, T> operator()(const T& x) const
           {
@@ -160,6 +149,7 @@
 
         private:
           const Policy& my_pol;
+ const function_object_bi_and_bi_prime& operator=(const function_object_bi_and_bi_prime&);
         };
       } // namespace airy_bi_zero_detail
     } // namespace airy_zero


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