// 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.
#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
{
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>(
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,
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>(
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(