From 382cd8fc4f16f1d24f71798a14da3244f837ae22 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Tue, 14 Jan 2025 20:04:31 +0100 Subject: [PATCH] More tests and minor corrections --- .../boost/multiprecision/cpp_double_fp.hpp | 19 ++-- test/test_various_edges.cpp | 89 ++++++++++++++++--- 2 files changed, 90 insertions(+), 18 deletions(-) diff --git a/include/boost/multiprecision/cpp_double_fp.hpp b/include/boost/multiprecision/cpp_double_fp.hpp index e120def03..db6b2237c 100644 --- a/include/boost/multiprecision/cpp_double_fp.hpp +++ b/include/boost/multiprecision/cpp_double_fp.hpp @@ -2030,14 +2030,18 @@ constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend< using c_type = typename std::common_type::type; - constexpr c_type my_max = static_cast(my_max_val); - const c_type ct = cpp_df_qf_detail::ccmath::fabs(backend.crep().first); + constexpr c_type my_max { static_cast(my_max_val) }; + constexpr c_type my_min { static_cast(my_min_val) }; + + const c_type ct { static_cast(backend.crep().first) }; if (ct > my_max) { - *result = backend.crep().first >= typename cpp_double_fp_backend::float_type(0U) - ? my_max_val - : my_min_val; + *result = my_max_val; + } + if (ct < my_min) + { + *result = my_min_val; } else { @@ -2091,8 +2095,9 @@ constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend using c_type = typename std::common_type::type; - const c_type my_max = static_cast(my_max_val); - const c_type ct = cpp_df_qf_detail::ccmath::fabs(backend.crep().first); + constexpr c_type my_max { static_cast(my_max_val) }; + + const c_type ct { static_cast(backend.crep().first) }; if (ct > my_max) { diff --git a/test/test_various_edges.cpp b/test/test_various_edges.cpp index 5617605c8..97d256673 100644 --- a/test/test_various_edges.cpp +++ b/test/test_various_edges.cpp @@ -85,9 +85,7 @@ namespace local using float_type = FloatType; using ctrl_type = boost::multiprecision::number, boost::multiprecision::et_off>; - std::mt19937_64 gen; - - gen.seed(time_point()); + std::mt19937_64 gen { time_point() }; auto dis = std::uniform_real_distribution @@ -285,6 +283,77 @@ namespace local BOOST_TEST(result_is_ok = ((conversion_result_min == (std::numeric_limits::min)()) && result_is_ok)); } + { + for(auto i = static_cast(UINT8_C(0)); i < static_cast(UINT8_C(16)); ++i) + { + static_cast(i); + + const float_type flt_factor_inf_pos { std::numeric_limits::infinity() * dis(gen) }; + const float_type flt_factor_inf_neg { std::numeric_limits::infinity() * -dis(gen) }; + + { + const float_type val_inf_pos_neg_add { flt_factor_inf_pos + flt_factor_inf_neg }; + + const bool result_inf_pos_neg_add_is_ok { isnan(val_inf_pos_neg_add) }; + + BOOST_TEST(result_inf_pos_neg_add_is_ok); + + result_is_ok = (result_inf_pos_neg_add_is_ok && result_is_ok); + } + + { + const float_type val_inf_pos_pos_add { flt_factor_inf_pos + -flt_factor_inf_neg }; + + const bool result_inf_pos_pos_add_is_ok { isinf(val_inf_pos_pos_add) }; + + BOOST_TEST(result_inf_pos_pos_add_is_ok); + + result_is_ok = (result_inf_pos_pos_add_is_ok && result_is_ok); + } + + { + const float_type val_inf_neg_neg_add { -flt_factor_inf_pos + (flt_factor_inf_neg) }; + + const bool result_inf_neg_neg_add_is_ok { isinf(val_inf_neg_neg_add) && signbit(val_inf_neg_neg_add) }; + + BOOST_TEST(result_inf_neg_neg_add_is_ok); + + result_is_ok = (result_inf_neg_neg_add_is_ok && result_is_ok); + } + + { + const float_type val_inf_pos_neg_sub { flt_factor_inf_pos - flt_factor_inf_neg }; + + const bool result_inf_pos_neg_sub_is_ok { isinf(val_inf_pos_neg_sub) }; + + BOOST_TEST(result_inf_pos_neg_sub_is_ok); + + result_is_ok = (result_inf_pos_neg_sub_is_ok && result_is_ok); + } + + { + const float_type val_inf_pos_pos_sub { flt_factor_inf_pos - (-flt_factor_inf_neg) }; + + const bool result_inf_pos_pos_sub_is_ok { isnan(val_inf_pos_pos_sub) }; + + BOOST_TEST(result_inf_pos_pos_sub_is_ok); + + result_is_ok = (result_inf_pos_pos_sub_is_ok && result_is_ok); + } + + { + const float_type val_inf_neg_neg_sub { -flt_factor_inf_pos - (flt_factor_inf_neg) }; + + const bool result_inf_neg_neg_sub_is_ok { isnan(val_inf_neg_neg_sub) }; + + BOOST_TEST(result_inf_neg_neg_sub_is_ok); + + result_is_ok = (result_inf_neg_neg_sub_is_ok && result_is_ok); + } + + } + } + return result_is_ok; } @@ -293,9 +362,7 @@ namespace local { using float_type = FloatType; - std::mt19937_64 gen; - - gen.seed(time_point()); + std::mt19937_64 gen { time_point() }; auto dis = std::uniform_real_distribution @@ -325,9 +392,7 @@ namespace local { using float_type = FloatType; - std::mt19937_64 gen; - - gen.seed(time_point()); + std::mt19937_64 gen { time_point() }; std::uniform_real_distribution dist @@ -723,11 +788,13 @@ namespace local { static_cast(index); - float_type arg_one_minus = + float_type arg_one_minus + { static_cast ( -static_cast(::my_one() * static_cast(dist(gen))) - ); + ) + }; const auto log_one_minus = log(arg_one_minus);