diff --git a/include/boost/math/special_functions/airy.hpp b/include/boost/math/special_functions/airy.hpp index 8bf3d59ab..80d82e491 100644 --- a/include/boost/math/special_functions/airy.hpp +++ b/include/boost/math/special_functions/airy.hpp @@ -159,9 +159,8 @@ T airy_ai_zero_imp(unsigned m, const Policy& pol) 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::has_quiet_NaN ? std::numeric_limits::quiet_NaN() : T(0)); + return policies::raise_domain_error(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(m); @@ -186,7 +185,7 @@ T airy_ai_zero_imp(unsigned m, const Policy& pol) // 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(pol), + boost::math::detail::airy_zero::airy_ai_zero_detail::function_object_ai_and_ai_prime(pol), guess_root, T(guess_root - tolerance), T(guess_root + tolerance), @@ -204,9 +203,8 @@ T airy_bi_zero_imp(unsigned m, const Policy& pol) 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::has_quiet_NaN ? std::numeric_limits::quiet_NaN() : T(0)); + return policies::raise_domain_error(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(m); @@ -220,7 +218,6 @@ T airy_bi_zero_imp(unsigned m, const Policy& pol) * ( log(float(std::numeric_limits::radix)) / 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; @@ -232,7 +229,7 @@ T airy_bi_zero_imp(unsigned m, const Policy& pol) // 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(pol), + boost::math::detail::airy_zero::airy_bi_zero_detail::function_object_bi_and_bi_prime(pol), guess_root, T(guess_root - tolerance), T(guess_root + tolerance), diff --git a/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp b/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp index b6f2ece12..d502f83dd 100644 --- a/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp +++ b/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp @@ -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 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 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 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 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