File indexing completed on 2025-09-18 08:48:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
0011 #define BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
0012
0013 #include <boost/math/tools/config.hpp>
0014 #include <boost/math/tools/numeric_limits.hpp>
0015 #include <boost/math/policies/error_handling.hpp>
0016 #include <boost/math/special_functions/fpclassify.hpp>
0017
0018
0019
0020 #ifdef _MSC_VER
0021 # pragma warning(push)
0022 # pragma warning(disable: 4702)
0023 #endif
0024
0025 namespace boost{ namespace math{ namespace detail
0026 {
0027
0028 template <class RealType, class Policy>
0029 BOOST_MATH_GPU_ENABLED inline bool check_probability(const char* function, RealType const& prob, RealType* result, const Policy& pol)
0030 {
0031 if((prob < 0) || (prob > 1) || !(boost::math::isfinite)(prob))
0032 {
0033 *result = policies::raise_domain_error<RealType>(
0034 function,
0035 "Probability argument is %1%, but must be >= 0 and <= 1 !", prob, pol);
0036 return false;
0037 }
0038 return true;
0039 }
0040
0041 template <class RealType, class Policy>
0042 BOOST_MATH_GPU_ENABLED inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
0043 {
0044 if((df <= 0) || !(boost::math::isfinite)(df))
0045 {
0046 *result = policies::raise_domain_error<RealType>(
0047 function,
0048 "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
0049 return false;
0050 }
0051 return true;
0052 }
0053
0054 template <class RealType, class Policy>
0055 BOOST_MATH_GPU_ENABLED inline bool check_df_gt0_to_inf(const char* function, RealType const& df, RealType* result, const Policy& pol)
0056 {
0057 if( (df <= 0) || (boost::math::isnan)(df) )
0058 {
0059 *result = policies::raise_domain_error<RealType>(
0060 function,
0061 "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
0062 return false;
0063 }
0064 return true;
0065 }
0066
0067
0068 template <class RealType, class Policy>
0069 BOOST_MATH_GPU_ENABLED inline bool check_scale(
0070 const char* function,
0071 RealType scale,
0072 RealType* result,
0073 const Policy& pol)
0074 {
0075 if((scale <= 0) || !(boost::math::isfinite)(scale))
0076 {
0077 *result = policies::raise_domain_error<RealType>(
0078 function,
0079 "Scale parameter is %1%, but must be > 0 !", scale, pol);
0080 return false;
0081 }
0082 return true;
0083 }
0084
0085 template <class RealType, class Policy>
0086 BOOST_MATH_GPU_ENABLED inline bool check_location(
0087 const char* function,
0088 RealType location,
0089 RealType* result,
0090 const Policy& pol)
0091 {
0092 if(!(boost::math::isfinite)(location))
0093 {
0094 *result = policies::raise_domain_error<RealType>(
0095 function,
0096 "Location parameter is %1%, but must be finite!", location, pol);
0097 return false;
0098 }
0099 return true;
0100 }
0101
0102 template <class RealType, class Policy>
0103 BOOST_MATH_GPU_ENABLED inline bool check_x(
0104 const char* function,
0105 RealType x,
0106 RealType* result,
0107 const Policy& pol)
0108 {
0109
0110
0111
0112
0113 if(!(boost::math::isfinite)(x))
0114 {
0115 *result = policies::raise_domain_error<RealType>(
0116 function,
0117 "Random variate x is %1%, but must be finite!", x, pol);
0118 return false;
0119 }
0120 return true;
0121 }
0122
0123 template <class RealType, class Policy>
0124 BOOST_MATH_GPU_ENABLED inline bool check_x_not_NaN(
0125 const char* function,
0126 RealType x,
0127 RealType* result,
0128 const Policy& pol)
0129 {
0130
0131
0132
0133 if ((boost::math::isnan)(x))
0134 {
0135 *result = policies::raise_domain_error<RealType>(
0136 function,
0137 "Random variate x is %1%, but must be finite or + or - infinity!", x, pol);
0138 return false;
0139 }
0140 return true;
0141 }
0142
0143 template <class RealType, class Policy>
0144 BOOST_MATH_GPU_ENABLED inline bool check_x_gt0(
0145 const char* function,
0146 RealType x,
0147 RealType* result,
0148 const Policy& pol)
0149 {
0150 if(x <= 0)
0151 {
0152 *result = policies::raise_domain_error<RealType>(
0153 function,
0154 "Random variate x is %1%, but must be > 0!", x, pol);
0155 return false;
0156 }
0157
0158 return true;
0159
0160
0161
0162 }
0163
0164 template <class RealType, class Policy>
0165 BOOST_MATH_GPU_ENABLED inline bool check_positive_x(
0166 const char* function,
0167 RealType x,
0168 RealType* result,
0169 const Policy& pol)
0170 {
0171 if(!(boost::math::isfinite)(x) || (x < 0))
0172 {
0173 *result = policies::raise_domain_error<RealType>(
0174 function,
0175 "Random variate x is %1%, but must be finite and >= 0!", x, pol);
0176 return false;
0177 }
0178 return true;
0179
0180
0181
0182 }
0183
0184 template <class RealType, class Policy>
0185 BOOST_MATH_GPU_ENABLED inline bool check_non_centrality(
0186 const char* function,
0187 RealType ncp,
0188 RealType* result,
0189 const Policy& pol)
0190 {
0191 BOOST_MATH_STATIC const RealType upper_limit = static_cast<RealType>((boost::math::numeric_limits<long long>::max)()) - boost::math::policies::get_max_root_iterations<Policy>();
0192
0193 if((ncp < 0) || !(boost::math::isfinite)(ncp) || ncp > upper_limit)
0194 {
0195 *result = policies::raise_domain_error<RealType>(
0196 function,
0197 "Non centrality parameter is %1%, but must be > 0, and a countable value such that x+1 != x", ncp, pol);
0198 return false;
0199 }
0200 return true;
0201 }
0202
0203 template <class RealType, class Policy>
0204 BOOST_MATH_GPU_ENABLED inline bool check_finite(
0205 const char* function,
0206 RealType x,
0207 RealType* result,
0208 const Policy& pol)
0209 {
0210 if(!(boost::math::isfinite)(x))
0211 {
0212 *result = policies::raise_domain_error<RealType>(
0213 function,
0214 "Parameter is %1%, but must be finite !", x, pol);
0215 return false;
0216 }
0217 return true;
0218 }
0219
0220 }
0221 }
0222 }
0223
0224 #ifdef _MSC_VER
0225 # pragma warning(pop)
0226 #endif
0227
0228 #endif