18
18
#include < boost/math/tools/traits.hpp>
19
19
#include < boost/math/tools/config.hpp>
20
20
#include < type_traits>
21
+ #include < stdexcept>
21
22
#include < cfloat>
22
23
#include < cstdint>
23
24
#include < cstring>
24
25
25
-
26
26
#if !defined(_CRAYC) && !defined(__CUDACC__) && (!defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3)))
27
27
#if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__)
28
28
#include " xmmintrin.h"
@@ -725,6 +725,7 @@ typename tools::promote_args<T, U>::type float_distance(const T& a, const U& b)
725
725
inline std::int32_t float_distance (float a, float b)
726
726
{
727
727
using std::abs ;
728
+ using std::isfinite;
728
729
constexpr auto tol = 2 * (std::numeric_limits<float >::min)();
729
730
730
731
// 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)
736
737
{
737
738
return static_cast <std::int32_t >(float_distance (a, b, policies::policy<>()));
738
739
}
740
+ else if (!(isfinite)(a) || !(isfinite)(b))
741
+ {
742
+ throw std::domain_error (" a and b must both be finite" );
743
+ }
739
744
740
745
static_assert (sizeof (float ) == sizeof (std::int32_t ), " float is incorrect size." );
741
746
@@ -757,6 +762,7 @@ inline std::int32_t float_distance(float a, float b)
757
762
inline std::int64_t float_distance (double a, double b)
758
763
{
759
764
using std::abs ;
765
+ using std::isfinite;
760
766
constexpr auto tol = 2 * (std::numeric_limits<double >::min)();
761
767
762
768
// 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)
768
774
{
769
775
return static_cast <std::int64_t >(float_distance (a, b, policies::policy<>()));
770
776
}
777
+ else if (!(isfinite)(a) || !(isfinite)(b))
778
+ {
779
+ throw std::domain_error (" a and b must both be finite" );
780
+ }
781
+
771
782
772
783
static_assert (sizeof (double ) == sizeof (std::int64_t ), " double is incorrect size." );
773
784
0 commit comments