|
22 | 22 | #include <cstdint>
|
23 | 23 | #include <cstring>
|
24 | 24 |
|
| 25 | +#if defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_MATH_STANDALONE) |
| 26 | +# include <boost/multiprecision/float128.hpp> |
| 27 | +# include <boost/multiprecision/detail/standalone_config.hpp> |
| 28 | +#endif |
| 29 | + |
25 | 30 |
|
26 | 31 | #if !defined(_CRAYC) && !defined(__CUDACC__) && (!defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3)))
|
27 | 32 | #if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__)
|
@@ -786,6 +791,39 @@ inline std::int64_t float_distance(double a, double b)
|
786 | 791 | return result;
|
787 | 792 | }
|
788 | 793 |
|
| 794 | +#if defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_MATH_STANDALONE) |
| 795 | +boost::multiprecision::int128_type float_distance(boost::multiprecision::float128 a, boost::multiprecision::float128 b) |
| 796 | +{ |
| 797 | + using std::abs; |
| 798 | + constexpr boost::multiprecision::float128 tol = 2 * (std::numeric_limits<boost::multiprecision::float128>::min)(); |
| 799 | + |
| 800 | + if (abs(a) == 0 || abs(b) == 0) |
| 801 | + { |
| 802 | + return static_cast<boost::multiprecision::int128_type>(float_distance(a, b, policies::policy<>())); |
| 803 | + } |
| 804 | + else if (abs(a) < tol || abs(b) < tol) |
| 805 | + { |
| 806 | + return static_cast<boost::multiprecision::int128_type>(float_distance(a, b, policies::policy<>())); |
| 807 | + } |
| 808 | + |
| 809 | + static_assert(sizeof(boost::multiprecision::int128_type) == sizeof(boost::multiprecision::float128), "128 bit float is the wrong size"); |
| 810 | + |
| 811 | + boost::multiprecision::int128_type ai; |
| 812 | + boost::multiprecision::int128_type bi; |
| 813 | + std::memcpy(&ai, &a, sizeof(boost::multiprecision::float128)); |
| 814 | + std::memcpy(&ai, &a, sizeof(boost::multiprecision::float128)); |
| 815 | + |
| 816 | + boost::multiprecision::int128_type result = bi - ai; |
| 817 | + |
| 818 | + if (ai < 0 || bi < 0) |
| 819 | + { |
| 820 | + result = -result; |
| 821 | + } |
| 822 | + |
| 823 | + return result; |
| 824 | +} |
| 825 | +#endif |
| 826 | + |
789 | 827 | namespace detail{
|
790 | 828 |
|
791 | 829 | template <class T, class Policy>
|
|
0 commit comments