Improve an example and also cover lines

This commit is contained in:
ckormanyos
2025-07-21 13:29:28 +02:00
parent 80609b22a2
commit 01f516eed3
3 changed files with 62 additions and 8 deletions
+11 -4
View File
@@ -30,7 +30,7 @@
//
// cpp_dec_float:
// result_is_ok_concurrent: true, calculation_time_concurrent: 2.1s
// result_is_ok_sequential: true, calculation_time_sequential: 15.2s
// result_is_ok_sequential: true, calculation_time_sequential: 14.7s
//
// cpp_bin_float:
// result_is_ok_concurrent: true, calculation_time_concurrent: 0.28s
@@ -52,6 +52,7 @@
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <thread>
#include <vector>
@@ -70,7 +71,7 @@
//#define BOOST_MP_EXERCISE_THREADING_BACKEND_TYPE BOOST_MP_EXERCISE_THREADING_BACKEND_MPFR_FLOAT
#endif
constexpr unsigned local_mp_digits { 301U };
constexpr unsigned local_mp_digits { 101U };
#if (BOOST_MP_EXERCISE_THREADING_BACKEND_TYPE == BOOST_MP_EXERCISE_THREADING_BACKEND_CPP_DEC_FLOAT)
#include <boost/multiprecision/cpp_dec_float.hpp>
@@ -379,7 +380,10 @@ bool log_agm_concurrent(float& calculation_time)
result_is_ok &= (close_fraction < tol);
}
std::cout << std::boolalpha << result_is_ok << std::endl;
std::stringstream strm { };
strm << std::boolalpha << result_is_ok;
std::cout << strm.str() << std::endl;
return result_is_ok;
}
@@ -440,7 +444,10 @@ bool log_agm_sequential(float& calculation_time)
result_is_ok &= (close_fraction < tol);
}
std::cout << std::boolalpha << result_is_ok << std::endl;
std::stringstream strm { };
strm << std::boolalpha << result_is_ok;
std::cout << strm.str() << std::endl;
return result_is_ok;
}
@@ -472,11 +472,14 @@ class cpp_dec_float // LCOV_EXCL_LINE This causes a false negative on lcov cover
exponent_type order() const
{
const bool bo_order_is_zero = ((!(isfinite)()) || (data[0] == static_cast<std::uint32_t>(0u)));
const bool
bo_order_is_zero
{
((!(isfinite)()) || (data[0] == static_cast<std::uint32_t>(0u)))
};
exponent_type prefix = limb_order(data[static_cast<std::size_t>(UINT8_C(0))]);
return (bo_order_is_zero ? static_cast<exponent_type>(0) : static_cast<exponent_type>(exp + prefix));
return (bo_order_is_zero ? static_cast<exponent_type>(0)
: static_cast<exponent_type>(exp + limb_order(data[static_cast<std::size_t>(UINT8_C(0))])));
}
#ifndef BOOST_MP_STANDALONE
+44
View File
@@ -622,6 +622,50 @@ namespace local
}
}
BOOST_IF_CONSTEXPR((std::numeric_limits<float>::digits >= 24) && std::numeric_limits<float_type>::is_specialized)
{
for(auto index = static_cast<unsigned>(UINT8_C(0)); index < static_cast<unsigned>(UINT8_C(16)); ++index)
{
// This test is specifically designed to pick up hard-to-reach lines
// in cpp_dec_float. Notice how the printed string is expected to have
// (or not have) rounding at the 8th fixed-point digit.
// N[1 + 1/2^4 + 1/2^5 + 1/2^7 + 1/2^9, 20]
const float flt_builtin { 1.1035156250000000000F };
const float_type delta = std::numeric_limits<float_type>::epsilon() * dis(gen) * static_cast<float>(index + 1U);
const float_type flt_val_base { flt_builtin };
const float_type flt_val_close_upper { flt_builtin + delta };
const float_type flt_val_close_lower { flt_builtin - delta };
{
std::stringstream strm { };
strm << std::fixed << std::setprecision(std::streamsize { INT8_C(8) }) << flt_val_base;
BOOST_TEST(strm.str() == "1.10351562");
}
{
std::stringstream strm { };
strm << std::fixed << std::setprecision(std::streamsize { INT8_C(8) }) << flt_val_close_upper;
BOOST_TEST(strm.str() > "1.10351562");
}
{
std::stringstream strm { };
strm << std::fixed << std::setprecision(std::streamsize { INT8_C(8) }) << flt_val_close_lower;
BOOST_TEST(strm.str() == "1.10351562");
}
}
}
return result_is_ok;
}