Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83316 - in trunk: boost/math/special_functions libs/math/test
From: john_at_[hidden]
Date: 2013-03-05 13:33:59


Author: johnmaddock
Date: 2013-03-05 13:33:58 EST (Tue, 05 Mar 2013)
New Revision: 83316
URL: http://svn.boost.org/trac/boost/changeset/83316

Log:
Tighten up error handling is tgamma_ratio.
Text files modified:
   trunk/boost/math/special_functions/gamma.hpp | 4 ++--
   trunk/libs/math/test/test_tgamma_ratio.hpp | 32 +++++++++++++++++++++++++++-----
   2 files changed, 29 insertions(+), 7 deletions(-)

Modified: trunk/boost/math/special_functions/gamma.hpp
==============================================================================
--- trunk/boost/math/special_functions/gamma.hpp (original)
+++ trunk/boost/math/special_functions/gamma.hpp 2013-03-05 13:33:58 EST (Tue, 05 Mar 2013)
@@ -1212,9 +1212,9 @@
 {
    BOOST_MATH_STD_USING
 
- if(x <= 0)
+ if((x <= tools::min_value<T>()) || (boost::math::isinf)(x))
       policies::raise_domain_error<T>("boost::math::tgamma_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got a=%1%).", x, pol);
- if(y <= 0)
+ if((y <= tools::min_value<T>()) || (boost::math::isinf)(y))
       policies::raise_domain_error<T>("boost::math::tgamma_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got b=%1%).", y, pol);
 
    if((x < max_factorial<T>::value) && (y < max_factorial<T>::value))

Modified: trunk/libs/math/test/test_tgamma_ratio.hpp
==============================================================================
--- trunk/libs/math/test/test_tgamma_ratio.hpp (original)
+++ trunk/libs/math/test/test_tgamma_ratio.hpp 2013-03-05 13:33:58 EST (Tue, 05 Mar 2013)
@@ -116,6 +116,11 @@
 
    do_test_tgamma_ratio<T>(tgamma_ratio_data, name, "tgamma ratios");
 
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4127 4756)
+#endif
    //
    // A few special spot tests:
    //
@@ -123,11 +128,28 @@
    T tol = boost::math::tools::epsilon<T>() * 20;
    if(std::numeric_limits<T>::max_exponent > 200)
    {
- BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(ldexp(T(1), -500), T(180.25)), 8.0113754557649679470816892372669519037339812035512e-178L, tol);
- BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(ldexp(T(1), -525), T(192.25)), 1.5966560279353205461166489184101261541784867035063e-197L, tol);
- BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(182.25), ldexp(T(1), -500)), 4.077990437521002194346763299159975185747917450788e+181L, tol);
- BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), ldexp(T(1), -525)), 1.2040790040958522422697601672703926839178050326148e+199L, tol);
- BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), T(194.75)), 0.00037151765099653237632823607820104961270831942138159L, tol);
+ BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(ldexp(T(1), -500), T(180.25)), T(8.0113754557649679470816892372669519037339812035512e-178L), tol);
+ BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(ldexp(T(1), -525), T(192.25)), T(1.5966560279353205461166489184101261541784867035063e-197L), tol);
+ BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(182.25), ldexp(T(1), -500)), T(4.077990437521002194346763299159975185747917450788e+181L), tol);
+ BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), ldexp(T(1), -525)), T(1.2040790040958522422697601672703926839178050326148e+199L), tol);
+ BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), T(194.75)), T(0.00037151765099653237632823607820104961270831942138159L), tol);
+ }
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(0, 2), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(2, 0), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(-1, 2), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(2, -1), std::domain_error);
+ if(std::numeric_limits<T>::has_denorm && (std::numeric_limits<T>::max_exponent == std::numeric_limits<long double>::max_exponent))
+ {
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(std::numeric_limits<T>::denorm_min(), 2), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(2, std::numeric_limits<T>::denorm_min()), std::domain_error);
+ }
+ if(std::numeric_limits<T>::has_infinity)
+ {
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(std::numeric_limits<T>::infinity(), 2), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::tgamma_ratio(2, std::numeric_limits<T>::infinity()), std::domain_error);
    }
+#ifdef _MSC_VER
+# pragma warning(pop)
+#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