|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82787 - in trunk: boost/math/special_functions libs/math/test
From: john_at_[hidden]
Date: 2013-02-08 12:28:50
Author: johnmaddock
Date: 2013-02-08 12:28:49 EST (Fri, 08 Feb 2013)
New Revision: 82787
URL: http://svn.boost.org/trac/boost/changeset/82787
Log:
Enable better error handling in bessel-zero code.
Text files modified:
trunk/boost/math/special_functions/bessel.hpp | 15 ++++++++++-----
trunk/libs/math/test/test_bessel_airy_zeros.cpp | 9 +++++----
2 files changed, 15 insertions(+), 9 deletions(-)
Modified: trunk/boost/math/special_functions/bessel.hpp
==============================================================================
--- trunk/boost/math/special_functions/bessel.hpp (original)
+++ trunk/boost/math/special_functions/bessel.hpp 2013-02-08 12:28:49 EST (Fri, 08 Feb 2013)
@@ -374,10 +374,13 @@
{
BOOST_MATH_STD_USING // ADL of std names, needed for log.
+ static const char* function = "boost::math::cyl_bessel_j_zero<%1%>(%1%, unsigned)";
// Handle negative order or if the zero'th zero is requested.
// Return NaN if NaN is available or return 0 if NaN is not available.
- if((v < T(0)) || (m == 0U))
- return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : T(0));
+ if(v < 0)
+ return policies::raise_domain_error<T>(function, "Order argument is %1%, but must be >= 0 !", v, pol);
+ if(m == 0)
+ return policies::raise_domain_error<T>(function, "Requested the %1%'th zero, but must be > 0 !", m, pol);
// Set up the initial guess for the upcoming root-finding.
const T guess_root = boost::math::detail::bessel_zero::cyl_bessel_j_zero_detail::initial_guess<T>(v, m);
@@ -411,10 +414,12 @@
{
BOOST_MATH_STD_USING // ADL of std names, needed for log.
+ static const char* function = "boost::math::cyl_neumann_zero<%1%>(%1%, unsigned)";
// Handle negative order or if the zero'th zero is requested.
- // Return NaN if NaN is available or return 0 if NaN is not available.
- if((v < T(0)) || (m == 0U))
- return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : T(0));
+ if(v < 0)
+ return policies::raise_domain_error<T>(function, "Order argument is %1%, but must be >= 0 !", v, pol);
+ if(m == 0)
+ return policies::raise_domain_error<T>(function, "Requested the %1%'th zero, but must be > 0 !", m, pol);
// Set up the initial guess for the upcoming root-finding.
const T guess_root = boost::math::detail::bessel_zero::cyl_neumann_zero_detail::initial_guess<T>(v, m);
Modified: trunk/libs/math/test/test_bessel_airy_zeros.cpp
==============================================================================
--- trunk/libs/math/test/test_bessel_airy_zeros.cpp (original)
+++ trunk/libs/math/test/test_bessel_airy_zeros.cpp 2013-02-08 12:28:49 EST (Fri, 08 Feb 2013)
@@ -90,10 +90,8 @@
using boost::math::cyl_bessel_j_zero; // (nu, j)
using boost::math::isnan;
- if (std::numeric_limits<RealType>::has_quiet_NaN)
- {
- BOOST_CHECK(isnan(cyl_bessel_j_zero(static_cast<RealType>(0), 0U))); // yes - returns NaN - is this right?
- }
+ BOOST_CHECK_THROW(cyl_bessel_j_zero(static_cast<RealType>(0), 0U), std::domain_error);
+ BOOST_CHECK_THROW(cyl_bessel_j_zero(static_cast<RealType>(-1), 2U), std::domain_error);
// Abuse with infinity and max.
if (std::numeric_limits<RealType>::has_infinity)
@@ -308,6 +306,9 @@
using boost::math::cyl_neumann_zero;
+ BOOST_CHECK_THROW(cyl_neumann_zero(static_cast<RealType>(0), 0U), std::domain_error);
+ BOOST_CHECK_THROW(cyl_neumann_zero(static_cast<RealType>(-1), 2U), std::domain_error);
+
BOOST_CHECK_CLOSE_FRACTION(cyl_neumann_zero(static_cast<RealType>(0), 1U), static_cast<RealType>(0.89357696627916752158488710205833824122514686193001L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(cyl_neumann_zero(static_cast<RealType>(1), 2U), static_cast<RealType>(5.4296810407941351327720051908525841965837574760291L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(cyl_neumann_zero(static_cast<RealType>(2), 3U), static_cast<RealType>(10.023477979360037978505391792081418280789658279097L), tolerance);
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