Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85790 - in trunk/boost/math: distributions distributions/detail policies
From: pbristow_at_[hidden]
Date: 2013-09-19 12:16:20


Author: pbristow
Date: 2013-09-19 12:16:20 EDT (Thu, 19 Sep 2013)
New Revision: 85790
URL: http://svn.boost.org/trac/boost/changeset/85790

Log:
Order of test for Trac #9126 in logistic and comments.

Text files modified:
   trunk/boost/math/distributions/detail/common_error_handling.hpp | 7 ++++---
   trunk/boost/math/distributions/logistic.hpp | 34 ++++++++++++++++++++--------------
   trunk/boost/math/policies/error_handling.hpp | 8 ++++----
   3 files changed, 28 insertions(+), 21 deletions(-)

Modified: trunk/boost/math/distributions/detail/common_error_handling.hpp
==============================================================================
--- trunk/boost/math/distributions/detail/common_error_handling.hpp Thu Sep 19 05:04:19 2013 (r85789)
+++ trunk/boost/math/distributions/detail/common_error_handling.hpp 2013-09-19 12:16:20 EDT (Thu, 19 Sep 2013) (r85790)
@@ -98,6 +98,10 @@
       RealType* result,
       const Policy& pol)
 {
+ // Note that this test catches both infinity and NaN.
+ // Some distributions permit x to be infinite, so these must be tested 1st and return,
+ // leaving this test to catch any NaNs.
+ // See Normal, Logistic and Cauchy for example.
    if(!(boost::math::isfinite)(x))
    {
       *result = policies::raise_domain_error<RealType>(
@@ -106,9 +110,6 @@
       return false;
    }
    return true;
- // Note that this test catches both infinity and NaN.
- // Some special cases permit x to be infinite, so these must be tested 1st,
- // leaving this test to catch any NaNs. see Normal and cauchy for example.
 } // bool check_x
 
 template <class RealType, class Policy>

Modified: trunk/boost/math/distributions/logistic.hpp
==============================================================================
--- trunk/boost/math/distributions/logistic.hpp Thu Sep 19 05:04:19 2013 (r85789)
+++ trunk/boost/math/distributions/logistic.hpp 2013-09-19 12:16:20 EDT (Thu, 19 Sep 2013) (r85790)
@@ -68,21 +68,15 @@
       using boost::math::tools::max_value;
       return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity
     }
-
-
+
     template <class RealType, class Policy>
     inline RealType pdf(const logistic_distribution<RealType, Policy>& dist, const RealType& x)
     {
+ static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)";
        RealType scale = dist.scale();
        RealType location = dist.location();
-
- static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)";
- if((boost::math::isinf)(x))
- {
- return 0; // pdf + and - infinity is zero.
- }
-
        RealType result = 0;
+
        if(false == detail::check_scale(function, scale , &result, Policy()))
        {
           return result;
@@ -91,6 +85,12 @@
        {
           return result;
        }
+
+ if((boost::math::isinf)(x))
+ {
+ return 0; // pdf + and - infinity is zero.
+ }
+
        if(false == detail::check_x(function, x, &result, Policy()))
        {
           return result;
@@ -186,18 +186,24 @@
        RealType x = c.param;
        static const char* function = "boost::math::cdf(const complement(logistic_distribution<%1%>&), %1%)";
 
- if((boost::math::isinf)(x))
- {
- if(x < 0) return 1; // cdf complement -infinity is unity.
- return 0; // cdf complement +infinity is zero
- }
        RealType result = 0;
        if(false == detail::check_scale(function, scale, &result, Policy()))
+ {
           return result;
+ }
        if(false == detail::check_location(function, location, &result, Policy()))
+ {
           return result;
+ }
+ if((boost::math::isinf)(x))
+ {
+ if(x < 0) return 1; // cdf complement -infinity is unity.
+ return 0; // cdf complement +infinity is zero.
+ }
        if(false == detail::check_x(function, x, &result, Policy()))
+ {
           return result;
+ }
        RealType power = (x - location) / scale;
        if(power > tools::log_max_value<RealType>())
           return 0;

Modified: trunk/boost/math/policies/error_handling.hpp
==============================================================================
--- trunk/boost/math/policies/error_handling.hpp Thu Sep 19 05:04:19 2013 (r85789)
+++ trunk/boost/math/policies/error_handling.hpp 2013-09-19 12:16:20 EDT (Thu, 19 Sep 2013) (r85790)
@@ -24,7 +24,7 @@
 # pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE
 # pragma warning(disable: 4512) // assignment operator could not be generated.
 // And warnings in error handling:
-# pragma warning(disable: 4702) // unreachable code
+# pragma warning(disable: 4702) // unreachable code.
 // Note that this only occurs when the compiler can deduce code is unreachable,
 // for example when policy macros are used to ignore errors rather than throw.
 #endif
@@ -70,7 +70,7 @@
 {
 //
 // Helper function to avoid binding rvalue to non-const-reference,
-// in other words a warning suppression mechansim:
+// in other words a warning suppression mechanism:
 //
 template <class Formatter, class Group>
 inline std::string do_format(Formatter f, const Group& g)
@@ -210,7 +210,7 @@
            const ::boost::math::policies::overflow_error< ::boost::math::policies::throw_on_error>&)
 {
    raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow");
- // we never get here:
+ // We should never get here:
    return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
 }
 
@@ -266,7 +266,7 @@
            const ::boost::math::policies::underflow_error< ::boost::math::policies::throw_on_error>&)
 {
    raise_error<std::underflow_error, T>(function, message ? message : "numeric underflow");
- // we never get here:
+ // We should never get here:
    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