]> git.donarmstrong.com Git - rsem.git/blobdiff - boost/math/distributions/detail/common_error_handling.hpp
Updated boost to v1.55.0
[rsem.git] / boost / math / distributions / detail / common_error_handling.hpp
index dad572a936b56a694cd43a9a36a2ecb766e8946f..91b06e626d72442bc3d7e04eb1dee2c419e0e461 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright John Maddock 2006, 2007.
-// Copyright Paul A. Bristow 2006, 2007.
+// Copyright Paul A. Bristow 2006, 2007, 2012.
 
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
@@ -12,6 +12,7 @@
 #include <boost/math/policies/error_handling.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 // using boost::math::isfinite;
+// using boost::math::isnan;
 
 namespace boost{ namespace math{ namespace detail
 {
@@ -31,7 +32,7 @@ inline bool check_probability(const char* function, RealType const& prob, RealTy
 
 template <class RealType, class Policy>
 inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
-{
+{ //  df > 0 but NOT +infinity allowed.
    if((df <= 0) || !(boost::math::isfinite)(df))
    {
       *result = policies::raise_domain_error<RealType>(
@@ -42,6 +43,20 @@ inline bool check_df(const char* function, RealType const& df, RealType* result,
    return true;
 }
 
+template <class RealType, class Policy>
+inline bool check_df_gt0_to_inf(const char* function, RealType const& df, RealType* result, const Policy& pol)
+{  // df > 0 or +infinity are allowed.
+   if( (df <= 0) || (boost::math::isnan)(df) )
+   { // is bad df <= 0 or NaN or -infinity.
+      *result = policies::raise_domain_error<RealType>(
+         function,
+         "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
+      return false;
+   }
+   return true;
+} // check_df_gt0_to_inf
+
+
 template <class RealType, class Policy>
 inline bool check_scale(
       const char* function,
@@ -83,6 +98,10 @@ inline bool check_x(
       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>(
@@ -91,10 +110,28 @@ inline bool check_x(
       return false;
    }
    return true;
+} // bool check_x
+
+template <class RealType, class Policy>
+inline bool check_x_gt0(
+      const char* function,
+      RealType x,
+      RealType* result,
+      const Policy& pol)
+{
+   if(x <= 0)
+   {
+      *result = policies::raise_domain_error<RealType>(
+         function,
+         "Random variate x is %1%, but must be > 0!", x, pol);
+      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.
-}
+   // leaving this test to catch any NaNs.  See Normal and cauchy for example.
+} // bool check_x_gt0
 
 template <class RealType, class Policy>
 inline bool check_positive_x(