Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52287 - trunk/boost/math/distributions/detail
From: john_at_[hidden]
Date: 2009-04-09 05:10:46


Author: johnmaddock
Date: 2009-04-09 05:10:45 EDT (Thu, 09 Apr 2009)
New Revision: 52287
URL: http://svn.boost.org/trac/boost/changeset/52287

Log:
Sort circuit evaluation when the result will be 0.
Text files modified:
   trunk/boost/math/distributions/detail/hypergeometric_pdf.hpp | 2 ++
   1 files changed, 2 insertions(+), 0 deletions(-)

Modified: trunk/boost/math/distributions/detail/hypergeometric_pdf.hpp
==============================================================================
--- trunk/boost/math/distributions/detail/hypergeometric_pdf.hpp (original)
+++ trunk/boost/math/distributions/detail/hypergeometric_pdf.hpp 2009-04-09 05:10:45 EDT (Thu, 09 Apr 2009)
@@ -107,6 +107,8 @@
    T result = pow(bases[sorted_indexes[0]] * exp(static_cast<T>(base_e_factors[sorted_indexes[0]])), exponents[sorted_indexes[0]]);
    for(unsigned i = 1; (i < 9) && (exponents[sorted_indexes[i]] > 0); ++i)
    {
+ if(result == 0)
+ return 0; // short circuit further evaluation
       if(exponents[sorted_indexes[i]] == 1)
          result *= bases[sorted_indexes[i]] * exp(static_cast<T>(base_e_factors[sorted_indexes[i]]));
       else if(exponents[sorted_indexes[i]] == 0.5f)


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