Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65714 - trunk/boost/math/distributions
From: john_at_[hidden]
Date: 2010-10-01 11:54:05


Author: johnmaddock
Date: 2010-10-01 11:54:03 EDT (Fri, 01 Oct 2010)
New Revision: 65714
URL: http://svn.boost.org/trac/boost/changeset/65714

Log:
Add more workaround code for numeric underflow/overflow.
Text files modified:
   trunk/boost/math/distributions/inverse_chi_squared.hpp | 5 ++++-
   trunk/boost/math/distributions/inverse_gamma.hpp | 5 ++++-
   2 files changed, 8 insertions(+), 2 deletions(-)

Modified: trunk/boost/math/distributions/inverse_chi_squared.hpp
==============================================================================
--- trunk/boost/math/distributions/inverse_chi_squared.hpp (original)
+++ trunk/boost/math/distributions/inverse_chi_squared.hpp 2010-10-01 11:54:03 EDT (Fri, 01 Oct 2010)
@@ -142,7 +142,10 @@
    // RealType shape = df /2; // inv_gamma shape
    // RealType scale = df * scale/2; // inv_gamma scale
    // RealType result = gamma_p_derivative(shape, scale / x, Policy()) * scale / (x * x);
- RealType result = gamma_p_derivative(df/2, df * scale/2 / x, Policy()) * df * scale/2;
+ RealType result = df * scale/2 / x;
+ if(result < tools::min_value<RealType>())
+ return 0; // Random variable is near enough infinite.
+ result = gamma_p_derivative(df/2, result, Policy()) * df * scale/2;
    if(result != 0) // prevent 0 / 0:
       result /= (x * x);
    return result;

Modified: trunk/boost/math/distributions/inverse_gamma.hpp
==============================================================================
--- trunk/boost/math/distributions/inverse_gamma.hpp (original)
+++ trunk/boost/math/distributions/inverse_gamma.hpp 2010-10-01 11:54:03 EDT (Fri, 01 Oct 2010)
@@ -163,7 +163,10 @@
    { // x bad.
       return result;
    }
- result = gamma_p_derivative(shape, scale / x, Policy()) * scale;
+ result = scale / x;
+ if(result < tools::min_value<RealType>())
+ return 0; // random variable is infinite or so close as to make no difference.
+ result = gamma_p_derivative(shape, result, Policy()) * scale;
    if(0 != result)
    {
       if(x < 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