From a8efc3a6b169be0840a21f7261ef384a19f16d12 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Wed, 15 Jan 2025 10:23:13 +0100 Subject: [PATCH] Try remove unused lines and more cover --- .../boost/multiprecision/cpp_double_fp.hpp | 96 ++++--------------- test/test_various_edges.cpp | 75 +++++++++++++-- 2 files changed, 88 insertions(+), 83 deletions(-) diff --git a/include/boost/multiprecision/cpp_double_fp.hpp b/include/boost/multiprecision/cpp_double_fp.hpp index 01aba6b3e..704953050 100644 --- a/include/boost/multiprecision/cpp_double_fp.hpp +++ b/include/boost/multiprecision/cpp_double_fp.hpp @@ -1987,48 +1987,28 @@ constexpr void eval_convert_to(unsigned long long* result, const cpp_double_fp_b } else { - BOOST_IF_CONSTEXPR(std::numeric_limits::digits >= cpp_df_qf_detail::ccmath::numeric_limits::digits) - { - *result = static_cast(backend.crep().first); - *result += static_cast(backend.crep().second); - } - else - { - cpp_double_fp_backend source = backend; - - *result = 0; - - for(auto digit_count = 0; - digit_count < cpp_double_fp_backend::my_digits; - digit_count += std::numeric_limits::digits) - { - const auto next = static_cast(source.crep().first); - - *result += next; - - eval_subtract(source, cpp_double_fp_backend(next)); - } - } + *result = static_cast(backend.crep().first); + *result += static_cast(backend.crep().second); } } #ifdef BOOST_HAS_INT128 template -constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend& backend) +constexpr void eval_convert_to(boost::int128_type* result, const cpp_double_fp_backend& backend) { const auto fpc = eval_fpclassify(backend); if (fpc != FP_NORMAL) { - *result = static_cast(backend.crep().first); + *result = static_cast(backend.crep().first); return; } - constexpr int128_type my_max_val = (((static_cast(1) << (sizeof(int128_type) * CHAR_BIT - 2)) - 1) << 1) + 1; - constexpr int128_type my_min_val = static_cast(-my_max_val - 1); + constexpr boost::int128_type my_max_val = (((static_cast(1) << (sizeof(boost::int128_type) * CHAR_BIT - 2)) - 1) << 1) + 1; + constexpr boost::int128_type my_min_val = static_cast(-my_max_val - 1); - using c_type = typename std::common_type::type; + using c_type = typename std::common_type::type; constexpr c_type my_max { static_cast(my_max_val) }; constexpr c_type my_min { static_cast(my_min_val) }; @@ -2045,51 +2025,31 @@ constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend< } else { - BOOST_IF_CONSTEXPR(static_cast(static_cast(sizeof(int128_type)) * CHAR_BIT) >= cpp_df_qf_detail::ccmath::numeric_limits::digits) - { - *result = static_cast(backend.crep().first); - *result += static_cast(backend.crep().second); - } - else - { - cpp_double_fp_backend source = backend; - - *result = 0; - - for(auto digit_count = static_cast(0); - digit_count < cpp_double_fp_backend::my_digits; - digit_count += static_cast(static_cast(sizeof(int128_type)) * CHAR_BIT)) - { - const auto next = static_cast(source.crep().first); - - *result += next; - - eval_subtract(source, cpp_double_fp_backend(next)); - } - } + *result = static_cast(backend.crep().first); + *result += static_cast(backend.crep().second); } } template -constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend& backend) +constexpr void eval_convert_to(boost::uint128_type* result, const cpp_double_fp_backend& backend) { const auto fpc = eval_fpclassify(backend); if (fpc != FP_NORMAL) { - *result = static_cast(backend.crep().first); + *result = static_cast(backend.crep().first); return; } - constexpr uint128_type my_max_val + constexpr boost::uint128_type my_max_val { (std::is_same::value && (cpp_df_qf_detail::ccmath::numeric_limits::digits == 24)) - ? static_cast(FLT_MAX) - : static_cast(~static_cast(0)) + ? static_cast(FLT_MAX) + : static_cast(~static_cast(0)) }; - using c_type = typename std::common_type::type; + using c_type = typename std::common_type::type; constexpr c_type my_max { static_cast(my_max_val) }; @@ -2101,28 +2061,10 @@ constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend } else { - BOOST_IF_CONSTEXPR(static_cast(static_cast(sizeof(uint128_type)) * CHAR_BIT) >= cpp_df_qf_detail::ccmath::numeric_limits::digits) - { - *result = static_cast(backend.crep().first); - *result += static_cast(backend.crep().second); - } - else - { - cpp_double_fp_backend source = backend; - - *result = 0; - - for(auto digit_count = static_cast(0); - digit_count < cpp_double_fp_backend::my_digits; - digit_count += static_cast(static_cast(sizeof(uint128_type)) * CHAR_BIT)) - { - const auto next = static_cast(source.crep().first); - - *result += next; + *result = static_cast(backend.crep().first); + *result += static_cast(backend.crep().second); - eval_subtract(source, cpp_double_fp_backend(next)); - } - } + *result = static_cast(*result); } } #endif @@ -2133,7 +2075,7 @@ constexpr typename ::std::enable_if::max)() }; + ctrl_type ctl_val { flt_val }; + + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(16)); ++i) + { + static_cast(i); + + float_type flt_factor { 1234.56e-12F * dis(gen) }; + + flt_val = flt_factor * flt_val; + ctl_val *= ctrl_type { flt_factor }; + + const bool result_mul_is_ok { local::is_close_fraction(flt_val, float_type { ctl_val }, std::numeric_limits::epsilon() * 32) }; + + BOOST_TEST(result_mul_is_ok); + + result_is_ok = (result_mul_is_ok && result_is_ok); + } + } + { float_type flt_val { }; ctrl_type ctl_val { }; @@ -222,9 +243,9 @@ namespace local const float_type inf_neg_02 { "-1e100002" }; const float_type inf_neg_03 { "-1e100003" }; - const float_type zero_01 { "1e-100001" }; - const float_type zero_02 { "1e-100002" }; - const float_type zero_03 { "1e-100003" }; + const float_type tiny_01 { "1e-100001" }; + const float_type tiny_02 { "1e-100002" }; + const float_type tiny_03 { "1e-100003" }; BOOST_TEST(result_is_ok = (isinf(inf_pos_01) && result_is_ok)); BOOST_TEST(result_is_ok = (isinf(inf_pos_02) && result_is_ok)); @@ -234,9 +255,9 @@ namespace local BOOST_TEST(result_is_ok = (isinf(inf_neg_02) && signbit(inf_neg_02) && result_is_ok)); BOOST_TEST(result_is_ok = (isinf(inf_neg_03) && signbit(inf_neg_03) && result_is_ok)); - BOOST_TEST(result_is_ok = ((fpclassify(zero_01) == FP_ZERO) && result_is_ok)); - BOOST_TEST(result_is_ok = ((fpclassify(zero_02) == FP_ZERO) && result_is_ok)); - BOOST_TEST(result_is_ok = ((fpclassify(zero_03) == FP_ZERO) && result_is_ok)); + BOOST_TEST(result_is_ok = ((fpclassify(tiny_01) == FP_ZERO) && result_is_ok)); + BOOST_TEST(result_is_ok = ((fpclassify(tiny_02) == FP_ZERO) && result_is_ok)); + BOOST_TEST(result_is_ok = ((fpclassify(tiny_03) == FP_ZERO) && result_is_ok)); } for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(8)); ++i) @@ -261,6 +282,21 @@ namespace local BOOST_TEST(result_is_ok = ((fpclassify(sub_result_zero) == FP_ZERO) && result_is_ok)); } + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(8)); ++i) + { + static_cast(i); + + float_type flt_numpos { ::my_one() * dis(gen) }; + float_type flt_numneg { ::my_one() * -dis(gen) }; + float_type flt_denom { ::my_zero() * dis(gen) }; + + const float_type div_result_zero_pos { flt_numpos / flt_denom }; + const float_type div_result_zero_neg { flt_numneg / flt_denom }; + + BOOST_TEST(result_is_ok = ((fpclassify(div_result_zero_pos) == FP_INFINITE) && result_is_ok)); + BOOST_TEST(result_is_ok = ((fpclassify(div_result_zero_neg) == FP_INFINITE) && signbit(div_result_zero_neg) && result_is_ok)); + } + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(8)); ++i) { static_cast(i); @@ -560,6 +596,33 @@ namespace local result_is_ok = (result_exp_small_is_ok && result_is_ok); } + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(16)); ++i) + { + static_cast(i); + + const float_type arg_small_scale { float_type {::my_one() / 24 } * static_cast(dist(gen)) }; + + const float_type result_exp_small_scale { exp(arg_small_scale) }; + + using ctrl_type = boost::multiprecision::number, boost::multiprecision::et_off>; + + const ctrl_type result_ctrl { exp(ctrl_type { arg_small_scale }) }; + + bool result_exp_small_scale_is_ok + { + local::is_close_fraction + ( + result_exp_small_scale, + float_type { result_ctrl }, + std::numeric_limits::epsilon() * 512 + ) + }; + + BOOST_TEST(result_exp_small_scale_is_ok); + + result_is_ok = (result_exp_small_scale_is_ok && result_is_ok); + } + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(16)); ++i) { static_cast(i);