Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80692 - in trunk: boost/math/special_functions libs/math/test
From: john_at_[hidden]
Date: 2012-09-24 12:23:07


Author: johnmaddock
Date: 2012-09-24 12:23:06 EDT (Mon, 24 Sep 2012)
New Revision: 80692
URL: http://svn.boost.org/trac/boost/changeset/80692

Log:
Fix atanh error handling.
Add extra tests to catch above bug.
Fixes #7415.
Text files modified:
   trunk/boost/math/special_functions/atanh.hpp | 12 ++++++------
   trunk/libs/math/test/atanh_test.hpp | 7 +++++++
   2 files changed, 13 insertions(+), 6 deletions(-)

Modified: trunk/boost/math/special_functions/atanh.hpp
==============================================================================
--- trunk/boost/math/special_functions/atanh.hpp (original)
+++ trunk/boost/math/special_functions/atanh.hpp 2012-09-24 12:23:06 EDT (Mon, 24 Sep 2012)
@@ -56,6 +56,12 @@
                   function,
                   "atanh requires x >= -1, but got x = %1%.", x, pol);
             }
+ else if(x > 1)
+ {
+ return policies::raise_domain_error<T>(
+ function,
+ "atanh requires x <= 1, but got x = %1%.", x, pol);
+ }
             else if(x < -1 + tools::epsilon<T>())
             {
                // -Infinity:
@@ -66,12 +72,6 @@
                // Infinity:
                return policies::raise_overflow_error<T>(function, 0, pol);
             }
- else if(x > 1)
- {
- return policies::raise_domain_error<T>(
- function,
- "atanh requires x <= 1, but got x = %1%.", x, pol);
- }
             else if(abs(x) >= tools::forth_root_epsilon<T>())
             {
                 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/

Modified: trunk/libs/math/test/atanh_test.hpp
==============================================================================
--- trunk/libs/math/test/atanh_test.hpp (original)
+++ trunk/libs/math/test/atanh_test.hpp 2012-09-24 12:23:06 EDT (Mon, 24 Sep 2012)
@@ -82,6 +82,13 @@
                 (static_cast<T>(4)));
         }
     }
+ //
+ // Error handling checks:
+ //
+ BOOST_CHECK_THROW(atanh(T(-1)), std::overflow_error);
+ BOOST_CHECK_THROW(atanh(T(1)), std::overflow_error);
+ BOOST_CHECK_THROW(atanh(T(-2)), std::domain_error);
+ BOOST_CHECK_THROW(atanh(T(2)), std::domain_error);
 }
 
 


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