Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57040 - in trunk: boost/math/special_functions libs/math/test
From: john_at_[hidden]
Date: 2009-10-21 08:27:38


Author: johnmaddock
Date: 2009-10-21 08:27:38 EDT (Wed, 21 Oct 2009)
New Revision: 57040
URL: http://svn.boost.org/trac/boost/changeset/57040

Log:
Improve ibeta error handling, and add new tests.
Text files modified:
   trunk/boost/math/special_functions/beta.hpp | 23 ++++++++++++++++-------
   trunk/libs/math/test/test_ibeta.cpp | 14 ++++++++++++++
   2 files changed, 30 insertions(+), 7 deletions(-)

Modified: trunk/boost/math/special_functions/beta.hpp
==============================================================================
--- trunk/boost/math/special_functions/beta.hpp (original)
+++ trunk/boost/math/special_functions/beta.hpp 2009-10-21 08:27:38 EDT (Wed, 21 Oct 2009)
@@ -884,21 +884,30 @@
    if(p_derivative)
       *p_derivative = -1; // value not set.
 
+ if((x < 0) || (x > 1))
+ policies::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol);
+
    if(normalised)
    {
       // extend to a few very special cases:
- if((a == 0) && (b != 0))
- return inv ? 0 : 1;
+ if(a == 0)
+ {
+ if(b == 0)
+ policies::raise_domain_error<T>(function, "The arguments a and b to the incomplete beta function cannot both be zero, with x=%1%.", x, pol);
+ if(b > 0)
+ return inv ? 0 : 1;
+ }
       else if(b == 0)
- return inv ? 1 : 0;
+ {
+ if(a > 0)
+ return inv ? 1 : 0;
+ }
    }
 
    if(a <= 0)
- policies::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a, pol);
+ policies::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be >= zero (got a=%1%).", a, pol);
    if(b <= 0)
- policies::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b, pol);
- if((x < 0) || (x > 1))
- policies::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol);
+ policies::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be >= zero (got b=%1%).", b, pol);
 
    if(x == 0)
    {

Modified: trunk/libs/math/test/test_ibeta.cpp
==============================================================================
--- trunk/libs/math/test/test_ibeta.cpp (original)
+++ trunk/libs/math/test/test_ibeta.cpp 2009-10-21 08:27:38 EDT (Wed, 21 Oct 2009)
@@ -536,6 +536,20 @@
          static_cast<T>(3),
          static_cast<T>(0.5)),
          pow(static_cast<T>(0.5), static_cast<T>(2)) * pow(static_cast<T>(0.5), static_cast<T>(1)) / boost::math::beta(static_cast<T>(2), static_cast<T>(3)), tolerance);
+
+ //
+ // Special cases and error handling:
+ //
+ BOOST_CHECK_EQUAL(::boost::math::ibeta(static_cast<T>(0), static_cast<T>(2), static_cast<T>(0.5)), static_cast<T>(1));
+ BOOST_CHECK_EQUAL(::boost::math::ibeta(static_cast<T>(3), static_cast<T>(0), static_cast<T>(0.5)), static_cast<T>(0));
+ BOOST_CHECK_EQUAL(::boost::math::ibetac(static_cast<T>(0), static_cast<T>(2), static_cast<T>(0.5)), static_cast<T>(0));
+ BOOST_CHECK_EQUAL(::boost::math::ibetac(static_cast<T>(4), static_cast<T>(0), static_cast<T>(0.5)), static_cast<T>(1));
+
+ BOOST_CHECK_THROW(::boost::math::ibetac(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0.5)), std::domain_error);
+ BOOST_CHECK_THROW(::boost::math::ibetac(static_cast<T>(-1), static_cast<T>(2), static_cast<T>(0.5)), std::domain_error);
+ BOOST_CHECK_THROW(::boost::math::ibetac(static_cast<T>(2), static_cast<T>(-2), static_cast<T>(0.5)), std::domain_error);
+ BOOST_CHECK_THROW(::boost::math::ibetac(static_cast<T>(2), static_cast<T>(2), static_cast<T>(-0.5)), std::domain_error);
+ BOOST_CHECK_THROW(::boost::math::ibetac(static_cast<T>(2), static_cast<T>(2), static_cast<T>(1.5)), std::domain_error);
 }
 
 int test_main(int, char* [])


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