1 // Copyright John Maddock 2006, 2007.
2 // Copyright Paul A. Bristow 2006, 2007.
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
10 #define BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
12 #include <boost/math/policies/error_handling.hpp>
13 #include <boost/math/special_functions/fpclassify.hpp>
14 // using boost::math::isfinite;
16 namespace boost{ namespace math{ namespace detail
19 template <class RealType, class Policy>
20 inline bool check_probability(const char* function, RealType const& prob, RealType* result, const Policy& pol)
22 if((prob < 0) || (prob > 1) || !(boost::math::isfinite)(prob))
24 *result = policies::raise_domain_error<RealType>(
26 "Probability argument is %1%, but must be >= 0 and <= 1 !", prob, pol);
32 template <class RealType, class Policy>
33 inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
35 if((df <= 0) || !(boost::math::isfinite)(df))
37 *result = policies::raise_domain_error<RealType>(
39 "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
45 template <class RealType, class Policy>
46 inline bool check_scale(
52 if((scale <= 0) || !(boost::math::isfinite)(scale))
53 { // Assume scale == 0 is NOT valid for any distribution.
54 *result = policies::raise_domain_error<RealType>(
56 "Scale parameter is %1%, but must be > 0 !", scale, pol);
62 template <class RealType, class Policy>
63 inline bool check_location(
69 if(!(boost::math::isfinite)(location))
71 *result = policies::raise_domain_error<RealType>(
73 "Location parameter is %1%, but must be finite!", location, pol);
79 template <class RealType, class Policy>
86 if(!(boost::math::isfinite)(x))
88 *result = policies::raise_domain_error<RealType>(
90 "Random variate x is %1%, but must be finite!", x, pol);
94 // Note that this test catches both infinity and NaN.
95 // Some special cases permit x to be infinite, so these must be tested 1st,
96 // leaving this test to catch any NaNs. see Normal and cauchy for example.
99 template <class RealType, class Policy>
100 inline bool check_positive_x(
101 const char* function,
106 if(!(boost::math::isfinite)(x) || (x < 0))
108 *result = policies::raise_domain_error<RealType>(
110 "Random variate x is %1%, but must be finite and >= 0!", x, pol);
114 // Note that this test catches both infinity and NaN.
115 // Some special cases permit x to be infinite, so these must be tested 1st,
116 // leaving this test to catch any NaNs. see Normal and cauchy for example.
119 template <class RealType, class Policy>
120 inline bool check_non_centrality(
121 const char* function,
126 if((ncp < 0) || !(boost::math::isfinite)(ncp))
127 { // Assume scale == 0 is NOT valid for any distribution.
128 *result = policies::raise_domain_error<RealType>(
130 "Non centrality parameter is %1%, but must be > 0 !", ncp, pol);
136 template <class RealType, class Policy>
137 inline bool check_finite(
138 const char* function,
143 if(!(boost::math::isfinite)(x))
144 { // Assume scale == 0 is NOT valid for any distribution.
145 *result = policies::raise_domain_error<RealType>(
147 "Parameter is %1%, but must be finite !", x, pol);
153 } // namespace detail
157 #endif // BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP