Try for even more cover lines

This commit is contained in:
ckormanyos
2025-07-04 19:58:46 +02:00
parent 64c8c8d40b
commit be9c643032
4 changed files with 63 additions and 20 deletions
+17 -12
View File
@@ -2017,12 +2017,14 @@ std::string cpp_dec_float<Digits10, ExponentType, Allocator>::str(std::intmax_t
const std::uint32_t ix = number_of_digits == 0 ? 0 : static_cast<std::uint32_t>(static_cast<std::uint32_t>(my_str[static_cast<std::string::size_type>(number_of_digits - 1)]) - static_cast<std::uint32_t>('0')); const std::uint32_t ix = number_of_digits == 0 ? 0 : static_cast<std::uint32_t>(static_cast<std::uint32_t>(my_str[static_cast<std::string::size_type>(number_of_digits - 1)]) - static_cast<std::uint32_t>('0'));
if ((ix & 1u) == 0) if ((ix & 1u) == 0)
{ {
// We have an even digit followed by a 5, so we might not actually need to round up // We have an even digit followed by a 5, so we might not actually
// if all the remaining digits are zero: // need to round up if all the remaining digits are zero:
if (my_str.find_first_not_of('0', static_cast<std::string::size_type>(number_of_digits + 1)) == std::string::npos) if (my_str.find_first_not_of('0', static_cast<std::string::size_type>(number_of_digits + 1)) == std::string::npos)
{ {
bool all_zeros = true; bool all_zeros = true;
// No none-zero trailing digits in the string, now check whatever parts we didn't convert to the string:
// There are no non-zero trailing digits in the string,
// now check whatever parts we didn't convert to the string:
for (std::size_t i = number_of_elements; i < data.size(); i++) for (std::size_t i = number_of_elements; i < data.size(); i++)
{ {
if (data[i]) if (data[i])
@@ -2139,11 +2141,12 @@ bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* con
// Get a possible +/- sign and remove it. // Get a possible +/- sign and remove it.
neg = false; neg = false;
if (my_str.size()) if (!my_str.empty())
{ {
if (my_str[0] == '-') if (my_str[0] == '-')
{ {
neg = true; neg = true;
my_str.erase(0, 1); my_str.erase(0, 1);
} }
else if (my_str[0] == '+') else if (my_str[0] == '+')
@@ -2151,23 +2154,25 @@ bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* con
my_str.erase(0, 1); my_str.erase(0, 1);
} }
} }
// //
// Special cases for infinities and NaN's: // Special cases for infinities and NaN's:
// //
if ((my_str == "inf") || (my_str == "INF") || (my_str == "infinity") || (my_str == "INFINITY")) if ((my_str == "inf") || (my_str == "INF") || (my_str == "infinity") || (my_str == "INFINITY"))
{ {
if (neg) const bool tmp_neg { neg };
{
*this = this->inf(); *this = this->inf();
this->negate();
} neg = tmp_neg;
else
*this = this->inf();
return true; return true;
} }
if ((my_str.size() >= 3) && ((my_str.substr(0, 3) == "nan") || (my_str.substr(0, 3) == "NAN") || (my_str.substr(0, 3) == "NaN"))) if ((my_str.size() >= 3) && ((my_str.substr(0, 3) == "nan") || (my_str.substr(0, 3) == "NAN") || (my_str.substr(0, 3) == "NaN")))
{ {
*this = this->nan(); *this = this->nan();
return true; return true;
} }
@@ -2485,7 +2490,7 @@ cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float(const double man
d -= static_cast<double>(n); d -= static_cast<double>(n);
d *= static_cast<double>(cpp_dec_float_elem_mask); d *= static_cast<double>(cpp_dec_float_elem_mask);
} }
} } // LCOV_EXCL_LINE
template <unsigned Digits10, class ExponentType, class Allocator> template <unsigned Digits10, class ExponentType, class Allocator>
template <class Float> template <class Float>
+8 -8
View File
@@ -3045,45 +3045,45 @@ void test_basic_conditionals(Real a, Real b)
{ {
if (a) if (a)
{ {
BOOST_ERROR("Unexpected non-zero result"); BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
} }
if (!a) if (!a)
{ {
} }
else else
{ {
BOOST_ERROR("Unexpected zero result"); BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
} }
b = 2; b = 2;
if (!b) if (!b)
{ {
BOOST_ERROR("Unexpected zero result"); BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
} }
if (b) if (b)
{ {
} }
else else
{ {
BOOST_ERROR("Unexpected non-zero result"); BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
} }
if (a && b) if (a && b)
{ {
BOOST_ERROR("Unexpected zero result"); BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
} }
if (!(a || b)) if (!(a || b))
{ {
BOOST_ERROR("Unexpected zero result"); BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
} }
if (a + b) if (a + b)
{ {
} }
else else
{ {
BOOST_ERROR("Unexpected zero result"); BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
} }
if (b - 2) if (b - 2)
{ {
BOOST_ERROR("Unexpected non-zero result"); BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
} }
} }
+6
View File
@@ -44,6 +44,7 @@ struct stopwatch
typename Clock::time_point m_start; typename Clock::time_point m_start;
}; };
// LCOV_EXCL_START
void print_flags(std::ios_base::fmtflags f) void print_flags(std::ios_base::fmtflags f)
{ {
std::cout << "Formatting flags were: "; std::cout << "Formatting flags were: ";
@@ -57,6 +58,7 @@ void print_flags(std::ios_base::fmtflags f)
std::cout << "showpos "; std::cout << "showpos ";
std::cout << std::endl; std::cout << std::endl;
} }
// LCOV_EXCL_STOP
template <class T> template <class T>
void test() void test()
@@ -88,6 +90,7 @@ void test()
const char* expect = string_data[j][col]; const char* expect = string_data[j][col];
if (ss.str() != expect) if (ss.str() != expect)
{ {
// LCOV_EXCL_START
std::cout << std::setprecision(20) << "Testing value " << val << std::endl; std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
print_flags(f[i]); print_flags(f[i]);
std::cout << "Precision is: " << prec << std::endl; std::cout << "Precision is: " << prec << std::endl;
@@ -95,6 +98,7 @@ void test()
std::cout << "Expected: " << expect << std::endl; std::cout << "Expected: " << expect << std::endl;
++boost::detail::test_errors(); ++boost::detail::test_errors();
mp_t(val).str(prec, f[i]); // for debugging mp_t(val).str(prec, f[i]); // for debugging
// LCOV_EXCL_STOP
} }
} }
} }
@@ -120,6 +124,7 @@ void test()
const char* expect = zeros[col]; const char* expect = zeros[col];
if (ss.str() != expect) if (ss.str() != expect)
{ {
// LCOV_EXCL_START
std::cout << std::setprecision(20) << "Testing value " << val << std::endl; std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
print_flags(f[i]); print_flags(f[i]);
std::cout << "Precision is: " << prec << std::endl; std::cout << "Precision is: " << prec << std::endl;
@@ -127,6 +132,7 @@ void test()
std::cout << "Expected: " << expect << std::endl; std::cout << "Expected: " << expect << std::endl;
++boost::detail::test_errors(); ++boost::detail::test_errors();
mp_t(val).str(prec, f[i]); // for debugging mp_t(val).str(prec, f[i]); // for debugging
// LCOV_EXCL_STOP
} }
} }
} }
+32
View File
@@ -358,6 +358,38 @@ namespace local
result_is_ok = (result_funky_strings_is_ok && result_is_ok); result_is_ok = (result_funky_strings_is_ok && result_is_ok);
} }
{
const std::initializer_list<std::string>
infty_strings_list
{
std::string("inf"), std::string("INF"), std::string("infinity"), std::string("INFINITY"),
std::string("+inf"), std::string("+INF"), std::string("+infinity"), std::string("+INFINITY"),
std::string("-inf"), std::string("-INF"), std::string("-infinity"), std::string("-INFINITY")
};
const std::vector<std::string> infty_strings(infty_strings_list);
std::size_t infty_count { };
for(const auto& str : infty_strings)
{
const float_type flt_from_inf_string(str);
const bool
result_infty_strings_is_ok
{
(boost::multiprecision::isinf)(flt_from_inf_string)
&& ((infty_count < std::size_t { UINT8_C(8) }) ? (!signbit(flt_from_inf_string)) : signbit(flt_from_inf_string))
};
++infty_count;
BOOST_TEST(result_infty_strings_is_ok);
result_is_ok = (result_infty_strings_is_ok && result_is_ok);
}
}
{ {
for(auto index = static_cast<unsigned>(UINT8_C(0)); index < static_cast<unsigned>(UINT8_C(16)); ++index) for(auto index = static_cast<unsigned>(UINT8_C(0)); index < static_cast<unsigned>(UINT8_C(16)); ++index)
{ {