X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=boost%2Fmath%2Fdistributions%2Fdetail%2Fcommon_error_handling.hpp;h=91b06e626d72442bc3d7e04eb1dee2c419e0e461;hp=dad572a936b56a694cd43a9a36a2ecb766e8946f;hb=2d71eb92104693ca9baa5a2e1c23eeca776d8fd3;hpb=da57529b92adbb7ae74a89861cb39fb35ac7c62d diff --git a/boost/math/distributions/detail/common_error_handling.hpp b/boost/math/distributions/detail/common_error_handling.hpp index dad572a..91b06e6 100644 --- a/boost/math/distributions/detail/common_error_handling.hpp +++ b/boost/math/distributions/detail/common_error_handling.hpp @@ -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 #include // 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 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( @@ -42,6 +43,20 @@ inline bool check_df(const char* function, RealType const& df, RealType* result, return true; } +template +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( + function, + "Degrees of freedom argument is %1%, but must be > 0 !", df, pol); + return false; + } + return true; +} // check_df_gt0_to_inf + + template 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( @@ -91,10 +110,28 @@ inline bool check_x( return false; } return true; +} // bool check_x + +template +inline bool check_x_gt0( + const char* function, + RealType x, + RealType* result, + const Policy& pol) +{ + if(x <= 0) + { + *result = policies::raise_domain_error( + 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 inline bool check_positive_x(