diff options
Diffstat (limited to 'boost/math/distributions/detail/common_error_handling.hpp')
-rw-r--r-- | boost/math/distributions/detail/common_error_handling.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/boost/math/distributions/detail/common_error_handling.hpp b/boost/math/distributions/detail/common_error_handling.hpp index 71a771e5a1..486fb0b5c8 100644 --- a/boost/math/distributions/detail/common_error_handling.hpp +++ b/boost/math/distributions/detail/common_error_handling.hpp @@ -14,6 +14,11 @@ // using boost::math::isfinite; // using boost::math::isnan; +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +#endif + namespace boost{ namespace math{ namespace detail { @@ -113,6 +118,26 @@ inline bool check_x( } // bool check_x template <class RealType, class Policy> +inline bool check_x_not_NaN( + const char* function, + RealType x, + RealType* result, + const Policy& pol) +{ + // Note that this test catches only NaN. + // Some distributions permit x to be infinite, leaving this test to catch any NaNs. + // See Normal, Logistic, Laplace and Cauchy for example. + if ((boost::math::isnan)(x)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate x is %1%, but must be finite or + or - infinity!", x, pol); + return false; + } + return true; +} // bool check_x_not_NaN + +template <class RealType, class Policy> inline bool check_x_gt0( const char* function, RealType x, @@ -191,4 +216,8 @@ inline bool check_finite( } // namespace math } // namespace boost +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + #endif // BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP |