@@ -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
@@ -737,6 +738,20 @@ inline std::int32_t float_distance(float a, float b)
737
738
return static_cast <std::int32_t >(float_distance (a, b, policies::policy<>()));
738
739
}
739
740
741
+ static const char * function = " float_distance<%1%>(%1%, %1%)" ;
742
+ if (!(boost::math::isfinite)(a))
743
+ {
744
+ return policies::raise_domain_error<float >(
745
+ function,
746
+ " Argument a must be finite, but got %1%" , a, policies::policy<>());
747
+ }
748
+ if (!(boost::math::isfinite)(b))
749
+ {
750
+ return policies::raise_domain_error<float >(
751
+ function,
752
+ " Argument b must be finite, but got %1%" , b, policies::policy<>());
753
+ }
754
+
740
755
static_assert (sizeof (float ) == sizeof (std::int32_t ), " float is incorrect size." );
741
756
742
757
std::int32_t ai;
@@ -757,6 +772,7 @@ inline std::int32_t float_distance(float a, float b)
757
772
inline std::int64_t float_distance (double a, double b)
758
773
{
759
774
using std::abs ;
775
+ using std::isfinite;
760
776
constexpr auto tol = 2 * (std::numeric_limits<double >::min)();
761
777
762
778
// 0, very small, and large magnitude distances all need special handling
@@ -768,6 +784,21 @@ inline std::int64_t float_distance(double a, double b)
768
784
{
769
785
return static_cast <std::int64_t >(float_distance (a, b, policies::policy<>()));
770
786
}
787
+
788
+ static const char * function = " float_distance<%1%>(%1%, %1%)" ;
789
+ if (!(boost::math::isfinite)(a))
790
+ {
791
+ return policies::raise_domain_error<double >(
792
+ function,
793
+ " Argument a must be finite, but got %1%" , a, policies::policy<>());
794
+ }
795
+ if (!(boost::math::isfinite)(b))
796
+ {
797
+ return policies::raise_domain_error<double >(
798
+ function,
799
+ " Argument b must be finite, but got %1%" , b, policies::policy<>());
800
+ }
801
+
771
802
772
803
static_assert (sizeof (double ) == sizeof (std::int64_t ), " double is incorrect size." );
773
804
0 commit comments