diff --git a/include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp b/include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp index 9b92a4a38..1f045420f 100644 --- a/include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp +++ b/include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp @@ -69,28 +69,30 @@ struct exact_arithmetic using float_type = FloatingPointType; using float_pair = std::pair; - using float_tuple = std::tuple; - static constexpr auto fast_sum(float_type a, float_type b) -> float_pair + static constexpr auto two_sum(const float_type a, const float_type b) -> float_pair { - // Exact addition of two floating point numbers, given |a| > |b| - const float_type a_plus_b = a + b; + const float_type hi { a + b }; + const float_type a1 { hi - b }; + const float_type b1 { hi - a1 }; - const float_pair result(a_plus_b, b - (a_plus_b - a)); - - return result; + return { hi, float_type { (a - a1) + (b - b1) } }; } - static constexpr void sum(float_pair& result, float_type a, float_type b) + static constexpr auto two_diff(const float_type a, const float_type b) -> float_pair { - // Exact addition of two floating point numbers - const float_type a_plus_b = a + b; - const float_type v = a_plus_b - a; + const float_type hi { a - b }; + const float_type a1 { hi + b }; + const float_type b1 { hi - a1 }; + + return { hi, float_type { (a - a1) - (b + b1) } }; + } - const float_pair tmp(a_plus_b, (a - (a_plus_b - v)) + (b - v)); + static constexpr auto two_hilo_sum(const float_type a, const float_type b) -> float_pair + { + const float_type hi { a + b }; - result.first = tmp.first; - result.second = tmp.second; + return { hi, float_type { b - (hi - a) } }; } static constexpr auto normalize(float_pair& result, float_type a, float_type b) -> void diff --git a/include/boost/multiprecision/cpp_double_fp.hpp b/include/boost/multiprecision/cpp_double_fp.hpp index fd763d7ad..d3c816a7b 100644 --- a/include/boost/multiprecision/cpp_double_fp.hpp +++ b/include/boost/multiprecision/cpp_double_fp.hpp @@ -478,13 +478,13 @@ class cpp_double_fp_backend const float_type xlo { data.second }; - data = two_sum(data.first, v.data.first); + data = arithmetic::two_sum(data.first, v.data.first); - const rep_type thi_tlo { two_sum(xlo, v.data.second) }; + const rep_type thi_tlo { arithmetic::two_sum(xlo, v.data.second) }; - data = two_hilo_sum(data.first, data.second + thi_tlo.first); + data = arithmetic::two_hilo_sum(data.first, data.second + thi_tlo.first); - data = two_hilo_sum(data.first, thi_tlo.second + data.second); + data = arithmetic::two_hilo_sum(data.first, thi_tlo.second + data.second); return *this; } @@ -539,13 +539,13 @@ class cpp_double_fp_backend const float_type xlo { data.second }; - data = two_diff(data.first, v.data.first); + data = arithmetic::two_diff(data.first, v.data.first); - const rep_type thi_tlo { two_diff(xlo, v.data.second) }; + const rep_type thi_tlo { arithmetic::two_diff(xlo, v.data.second) }; - data = two_hilo_sum(data.first, data.second + thi_tlo.first); + data = arithmetic::two_hilo_sum(data.first, data.second + thi_tlo.first); - data = two_hilo_sum(data.first, thi_tlo.second + data.second); + data = arithmetic::two_hilo_sum(data.first, thi_tlo.second + data.second); return *this; } @@ -975,7 +975,7 @@ class cpp_double_fp_backend return cpp_double_fp_backend ( - arithmetic::fast_sum + arithmetic::two_hilo_sum ( static_cast ( @@ -1065,31 +1065,6 @@ class cpp_double_fp_backend bool rd_string(const char* pstr); - static constexpr rep_type two_sum(const float_type a, const float_type b) - { - const float_type hi { a + b }; - const float_type a1 { hi - b }; - const float_type b1 { hi - a1 }; - - return { hi, float_type { (a - a1) + (b - b1) } }; - } - - static constexpr rep_type two_diff(const float_type a, const float_type b) - { - const float_type hi { a - b }; - const float_type a1 { hi + b }; - const float_type b1 { hi - a1 }; - - return { hi, float_type { (a - a1) - (b + b1) } }; - } - - static constexpr rep_type two_hilo_sum(const float_type a, const float_type b) - { - const float_type hi { a + b }; - - return { hi, float_type { b - (hi - a) } }; - } - template ::value && ((cpp_df_qf_detail::ccmath::numeric_limits::digits10 * 2) < 16))>::type const*> friend constexpr void eval_exp(cpp_double_fp_backend& result, const cpp_double_fp_backend& x);