Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74918 - in trunk: boost/math/special_functions libs/math/test
From: john_at_[hidden]
Date: 2011-10-11 13:28:14


Author: johnmaddock
Date: 2011-10-11 13:28:13 EDT (Tue, 11 Oct 2011)
New Revision: 74918
URL: http://svn.boost.org/trac/boost/changeset/74918

Log:
Change nextafter and related functions to handle infinities as arguments the same way as GLIBC and MSVC.
Fixes #5823.
Text files modified:
   trunk/boost/math/special_functions/next.hpp | 12 ++++++++++--
   trunk/libs/math/test/test_next.cpp | 18 ++++++++++++++++++
   2 files changed, 28 insertions(+), 2 deletions(-)

Modified: trunk/boost/math/special_functions/next.hpp
==============================================================================
--- trunk/boost/math/special_functions/next.hpp (original)
+++ trunk/boost/math/special_functions/next.hpp 2011-10-11 13:28:13 EDT (Tue, 11 Oct 2011)
@@ -55,9 +55,13 @@
    static const char* function = "float_next<%1%>(%1%)";
 
    if(!(boost::math::isfinite)(val))
+ {
+ if(val < 0)
+ return -tools::max_value<T>();
       return policies::raise_domain_error<T>(
          function,
          "Argument must be finite, but got %1%", val, pol);
+ }
 
    if(val >= tools::max_value<T>())
       return policies::raise_overflow_error<T>(function, 0, pol);
@@ -79,7 +83,7 @@
 {
    static const char* function = "float_next<%1%>(%1%)";
 
- if(!(boost::math::isfinite)(val))
+ if(!(boost::math::isfinite)(val) && (val > 0))
       return policies::raise_domain_error<double>(
          function,
          "Argument must be finite, but got %1%", val, pol);
@@ -105,9 +109,13 @@
    static const char* function = "float_prior<%1%>(%1%)";
 
    if(!(boost::math::isfinite)(val))
+ {
+ if(val > 0)
+ return tools::max_value<T>();
       return policies::raise_domain_error<T>(
          function,
          "Argument must be finite, but got %1%", val, pol);
+ }
 
    if(val <= -tools::max_value<T>())
       return -policies::raise_overflow_error<T>(function, 0, pol);
@@ -130,7 +138,7 @@
 {
    static const char* function = "float_prior<%1%>(%1%)";
 
- if(!(boost::math::isfinite)(val))
+ if(!(boost::math::isfinite)(val) && (val < 0))
       return policies::raise_domain_error<double>(
          function,
          "Argument must be finite, but got %1%", val, pol);

Modified: trunk/libs/math/test/test_next.cpp
==============================================================================
--- trunk/libs/math/test/test_next.cpp (original)
+++ trunk/libs/math/test/test_next.cpp 2011-10-11 13:28:13 EDT (Tue, 11 Oct 2011)
@@ -108,6 +108,23 @@
       BOOST_CHECK_EQUAL(boost::math::float_advance(val, primes[i]), v1);
       BOOST_CHECK_EQUAL(boost::math::float_advance(val, -primes[i]), v2);
    }
+ if(std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::has_infinity))
+ {
+ BOOST_CHECK_EQUAL(boost::math::float_prior(std::numeric_limits<T>::infinity()), (std::numeric_limits<T>::max)());
+ BOOST_CHECK_EQUAL(boost::math::float_next(-std::numeric_limits<T>::infinity()), -(std::numeric_limits<T>::max)());
+ BOOST_CHECK_THROW(boost::math::float_prior(-std::numeric_limits<T>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(boost::math::float_next(std::numeric_limits<T>::infinity()), std::domain_error);
+ if(boost::math::policies:: BOOST_MATH_OVERFLOW_ERROR_POLICY == boost::math::policies::throw_on_error)
+ {
+ BOOST_CHECK_THROW(boost::math::float_prior(-(std::numeric_limits<T>::max)()), std::overflow_error);
+ BOOST_CHECK_THROW(boost::math::float_next((std::numeric_limits<T>::max)()), std::overflow_error);
+ }
+ else
+ {
+ BOOST_CHECK_EQUAL(boost::math::float_prior(-(std::numeric_limits<T>::max)()), -std::numeric_limits<T>::infinity());
+ BOOST_CHECK_EQUAL(boost::math::float_next((std::numeric_limits<T>::max)()), std::numeric_limits<T>::infinity());
+ }
+ }
 }
 
 int test_main(int, char* [])
@@ -121,3 +138,4 @@
    return 0;
 }
 
+


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