diff --git a/include/boost/math/special_functions/next.hpp b/include/boost/math/special_functions/next.hpp index 0da7aca475..2dc4f31b78 100644 --- a/include/boost/math/special_functions/next.hpp +++ b/include/boost/math/special_functions/next.hpp @@ -18,11 +18,11 @@ #include #include #include +#include #include #include #include - #if !defined(_CRAYC) && !defined(__CUDACC__) && (!defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3))) #if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__) #include "xmmintrin.h" @@ -725,6 +725,7 @@ typename tools::promote_args::type float_distance(const T& a, const U& b) inline std::int32_t float_distance(float a, float b) { using std::abs; + using std::isfinite; constexpr auto tol = 2 * (std::numeric_limits::min)(); // 0, very small, and large magnitude distances all need special handling @@ -736,6 +737,10 @@ inline std::int32_t float_distance(float a, float b) { return static_cast(float_distance(a, b, policies::policy<>())); } + else if (!(isfinite)(a) || !(isfinite)(b)) + { + throw std::domain_error("a and b must both be finite"); + } static_assert(sizeof(float) == sizeof(std::int32_t), "float is incorrect size."); @@ -757,6 +762,7 @@ inline std::int32_t float_distance(float a, float b) inline std::int64_t float_distance(double a, double b) { using std::abs; + using std::isfinite; constexpr auto tol = 2 * (std::numeric_limits::min)(); // 0, very small, and large magnitude distances all need special handling @@ -768,6 +774,11 @@ inline std::int64_t float_distance(double a, double b) { return static_cast(float_distance(a, b, policies::policy<>())); } + else if (!(isfinite)(a) || !(isfinite)(b)) + { + throw std::domain_error("a and b must both be finite"); + } + static_assert(sizeof(double) == sizeof(std::int64_t), "double is incorrect size.");