mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-19 04:22:11 +00:00
Try for even more cover lines
This commit is contained in:
@@ -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'));
|
||||
if ((ix & 1u) == 0)
|
||||
{
|
||||
// We have an even digit followed by a 5, so we might not actually need to round up
|
||||
// if all the remaining digits are zero:
|
||||
// We have an even digit followed by a 5, so we might not actually
|
||||
// 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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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.
|
||||
neg = false;
|
||||
|
||||
if (my_str.size())
|
||||
if (!my_str.empty())
|
||||
{
|
||||
if (my_str[0] == '-')
|
||||
{
|
||||
neg = true;
|
||||
|
||||
my_str.erase(0, 1);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Special cases for infinities and NaN's:
|
||||
//
|
||||
if ((my_str == "inf") || (my_str == "INF") || (my_str == "infinity") || (my_str == "INFINITY"))
|
||||
{
|
||||
if (neg)
|
||||
{
|
||||
*this = this->inf();
|
||||
this->negate();
|
||||
}
|
||||
else
|
||||
*this = this->inf();
|
||||
const bool tmp_neg { neg };
|
||||
|
||||
*this = this->inf();
|
||||
|
||||
neg = tmp_neg;
|
||||
|
||||
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")))
|
||||
{
|
||||
*this = this->nan();
|
||||
|
||||
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>(cpp_dec_float_elem_mask);
|
||||
}
|
||||
}
|
||||
} // LCOV_EXCL_LINE
|
||||
|
||||
template <unsigned Digits10, class ExponentType, class Allocator>
|
||||
template <class Float>
|
||||
|
||||
@@ -3045,45 +3045,45 @@ void test_basic_conditionals(Real a, Real b)
|
||||
{
|
||||
if (a)
|
||||
{
|
||||
BOOST_ERROR("Unexpected non-zero result");
|
||||
BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (!a)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("Unexpected zero result");
|
||||
BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
b = 2;
|
||||
if (!b)
|
||||
{
|
||||
BOOST_ERROR("Unexpected zero result");
|
||||
BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (b)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("Unexpected non-zero result");
|
||||
BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (a && b)
|
||||
{
|
||||
BOOST_ERROR("Unexpected zero result");
|
||||
BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (!(a || b))
|
||||
{
|
||||
BOOST_ERROR("Unexpected zero result");
|
||||
BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (a + b)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("Unexpected zero result");
|
||||
BOOST_ERROR("Unexpected zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
if (b - 2)
|
||||
{
|
||||
BOOST_ERROR("Unexpected non-zero result");
|
||||
BOOST_ERROR("Unexpected non-zero result"); // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ struct stopwatch
|
||||
typename Clock::time_point m_start;
|
||||
};
|
||||
|
||||
// LCOV_EXCL_START
|
||||
void print_flags(std::ios_base::fmtflags f)
|
||||
{
|
||||
std::cout << "Formatting flags were: ";
|
||||
@@ -57,6 +58,7 @@ void print_flags(std::ios_base::fmtflags f)
|
||||
std::cout << "showpos ";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
template <class T>
|
||||
void test()
|
||||
@@ -88,6 +90,7 @@ void test()
|
||||
const char* expect = string_data[j][col];
|
||||
if (ss.str() != expect)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
|
||||
print_flags(f[i]);
|
||||
std::cout << "Precision is: " << prec << std::endl;
|
||||
@@ -95,6 +98,7 @@ void test()
|
||||
std::cout << "Expected: " << expect << std::endl;
|
||||
++boost::detail::test_errors();
|
||||
mp_t(val).str(prec, f[i]); // for debugging
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +124,7 @@ void test()
|
||||
const char* expect = zeros[col];
|
||||
if (ss.str() != expect)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
|
||||
print_flags(f[i]);
|
||||
std::cout << "Precision is: " << prec << std::endl;
|
||||
@@ -127,6 +132,7 @@ void test()
|
||||
std::cout << "Expected: " << expect << std::endl;
|
||||
++boost::detail::test_errors();
|
||||
mp_t(val).str(prec, f[i]); // for debugging
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +358,38 @@ namespace local
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user