1818#include < boost/math/tools/traits.hpp>
1919#include < boost/math/tools/config.hpp>
2020#include < type_traits>
21+ #include < stdexcept>
2122#include < cfloat>
2223#include < cstdint>
2324#include < cstring>
2425
25-
2626#if !defined(_CRAYC) && !defined(__CUDACC__) && (!defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3)))
2727#if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__)
2828#include " xmmintrin.h"
@@ -725,6 +725,7 @@ typename tools::promote_args<T, U>::type float_distance(const T& a, const U& b)
725725inline std::int32_t float_distance (float a, float b)
726726{
727727 using std::abs;
728+ using std::isfinite;
728729 constexpr auto tol = 2 * (std::numeric_limits<float >::min)();
729730
730731 // 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)
736737 {
737738 return static_cast <std::int32_t >(float_distance (a, b, policies::policy<>()));
738739 }
740+ else if (!(isfinite)(a) || !(isfinite)(b))
741+ {
742+ throw std::domain_error (" a and b must both be finite" );
743+ }
739744
740745 static_assert (sizeof (float ) == sizeof (std::int32_t ), " float is incorrect size." );
741746
@@ -757,6 +762,7 @@ inline std::int32_t float_distance(float a, float b)
757762inline std::int64_t float_distance (double a, double b)
758763{
759764 using std::abs;
765+ using std::isfinite;
760766 constexpr auto tol = 2 * (std::numeric_limits<double >::min)();
761767
762768 // 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)
768774 {
769775 return static_cast <std::int64_t >(float_distance (a, b, policies::policy<>()));
770776 }
777+ else if (!(isfinite)(a) || !(isfinite)(b))
778+ {
779+ throw std::domain_error (" a and b must both be finite" );
780+ }
781+
771782
772783 static_assert (sizeof (double ) == sizeof (std::int64_t ), " double is incorrect size." );
773784
0 commit comments