Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84997 - in trunk: boost/multiprecision/detail/functions libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-07-10 12:08:13


Author: johnmaddock
Date: 2013-07-10 12:08:12 EDT (Wed, 10 Jul 2013)
New Revision: 84997
URL: http://svn.boost.org/trac/boost/changeset/84997

Log:
Fix bug in eval_pow that causes 0^N to be none-zero.
Fixes #8798.

Text files modified:
   trunk/boost/multiprecision/detail/functions/pow.hpp | 13 ++++++++++++-
   trunk/libs/multiprecision/test/test_pow.cpp | 11 +++++++++++
   2 files changed, 23 insertions(+), 1 deletions(-)

Modified: trunk/boost/multiprecision/detail/functions/pow.hpp
==============================================================================
--- trunk/boost/multiprecision/detail/functions/pow.hpp Wed Jul 10 02:44:14 2013 (r84996)
+++ trunk/boost/multiprecision/detail/functions/pow.hpp 2013-07-10 12:08:12 EDT (Wed, 10 Jul 2013) (r84997)
@@ -427,7 +427,18 @@
       result = x;
       return;
    case FP_ZERO:
- result = si_type(1);
+ switch(eval_fpclassify(a))
+ {
+ case FP_ZERO:
+ result = si_type(1);
+ break;
+ case FP_NAN:
+ result = a;
+ break;
+ default:
+ result = x;
+ break;
+ }
       return;
    case FP_NAN:
       result = x;

Modified: trunk/libs/multiprecision/test/test_pow.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_pow.cpp Wed Jul 10 02:44:14 2013 (r84996)
+++ trunk/libs/multiprecision/test/test_pow.cpp 2013-07-10 12:08:12 EDT (Wed, 10 Jul 2013) (r84997)
@@ -572,6 +572,17 @@
       }
    }
    std::cout << "Max error was: " << max_err << std::endl;
+ //
+ // Special cases come last:
+ //
+ BOOST_CHECK_EQUAL(pow(T(0), T(0)), 1);
+ BOOST_CHECK_EQUAL(pow(T(0), 0), 1);
+ BOOST_CHECK_EQUAL(pow(T(0), T(2)), 0);
+ BOOST_CHECK_EQUAL(pow(T(0), 2), 0);
+ BOOST_CHECK_EQUAL(pow(T(1), T(0)), 1);
+ BOOST_CHECK_EQUAL(pow(T(1), 0), 1);
+ BOOST_CHECK_EQUAL(pow(T(1), T(2)), 1);
+ BOOST_CHECK_EQUAL(pow(T(1), 2), 1);
 }
 
 


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