2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-28 07:22:12 +00:00

Added exception handling to airy_ai_zero() and airy_bi_zero().

[SVN r83168]
This commit is contained in:
Christopher Kormanyos
2013-02-26 20:34:23 +00:00
parent 99f141004b
commit fd836efe63
2 changed files with 12 additions and 25 deletions

View File

@@ -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<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 @@ 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<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 @@ 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<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);
@@ -220,7 +218,6 @@ T airy_bi_zero_imp(unsigned m, const Policy& pol)
* ( log(float(std::numeric_limits<T>::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<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),

View File

@@ -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