Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions include/boost/decimal/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ constexpr auto to_chars_nonfinite(char* first, char* last, const TargetDecimalTy
}
}

return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE : Should be unreachable
return {last, std::errc::value_too_large};
case FP_NAN:
if (issignaling(value) && buffer_len >= 9)
{
Expand Down Expand Up @@ -238,7 +238,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
// Dummy check the bounds
if (BOOST_DECIMAL_UNLIKELY(buffer_size < real_precision))
{
return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE
return {last, std::errc::value_too_large};
}

using uint_type = std::conditional_t<(std::numeric_limits<typename TargetDecimalType::significand_type>::digits >
Expand All @@ -253,7 +253,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
// which we have already checked for
if (BOOST_DECIMAL_UNLIKELY(!r))
{
return r; // LCOV_EXCL_LINE
return r;
}

auto current_digits {r.ptr - (first + 1)};
Expand All @@ -273,7 +273,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
const auto total_length {total_buffer_length<TargetDecimalType>(static_cast<int>(current_digits), exp, is_neg)};
if (BOOST_DECIMAL_UNLIKELY(total_length > buffer_size))
{
return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE
return {last, std::errc::value_too_large};
}

// Insert our decimal point (or don't in the 1 digit case)
Expand Down Expand Up @@ -309,7 +309,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec

if (BOOST_DECIMAL_UNLIKELY(!exp_r))
{
return exp_r; // LCOV_EXCL_LINE
return exp_r;
}

return {exp_r.ptr, std::errc{}};
Expand Down Expand Up @@ -374,7 +374,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
}
else if (significand_digits > local_precision + 1)
{
const auto original_sig = significand; // LCOV_EXCL_LINE : False negative
const auto original_sig = significand;
fenv_round<TargetDecimalType>(significand);
if (remove_trailing_zeros(original_sig + 1U).trimmed_number == 1U)
{
Expand Down Expand Up @@ -406,7 +406,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
// Only real reason we will hit this is a buffer overflow
if (BOOST_DECIMAL_UNLIKELY(!r))
{
return r; // LCOV_EXCL_LINE
return r;
}

const auto current_digits = r.ptr - (first + 1) - 1;
Expand Down Expand Up @@ -478,7 +478,7 @@ constexpr auto to_chars_scientific_impl(char* first, char* last, const TargetDec
r = to_chars_integer_impl<int>(first, last, abs_exp);
if (BOOST_DECIMAL_UNLIKELY(!r))
{
return r; // LCOV_EXCL_LINE
return r;
}

return {r.ptr, std::errc()};
Expand Down Expand Up @@ -520,7 +520,7 @@ constexpr auto to_chars_fixed_impl(char* first, char* last, const TargetDecimalT

if (BOOST_DECIMAL_UNLIKELY(!r))
{
return r; // LCOV_EXCL_LINE
return r;
}

const auto num_digits {r.ptr - current};
Expand All @@ -536,7 +536,7 @@ constexpr auto to_chars_fixed_impl(char* first, char* last, const TargetDecimalT
{
if (BOOST_DECIMAL_UNLIKELY(buffer_size < (current - first) + num_digits + exp))
{
return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE
return {last, std::errc::value_too_large};
}

detail::memset(r.ptr, '0', static_cast<std::size_t>(exp));
Expand All @@ -546,7 +546,7 @@ constexpr auto to_chars_fixed_impl(char* first, char* last, const TargetDecimalT
{
if (BOOST_DECIMAL_UNLIKELY(buffer_size < (current - first) + num_digits + 1))
{
return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE
return {last, std::errc::value_too_large};
}

const auto decimal_pos {num_digits - abs_exp};
Expand All @@ -560,7 +560,7 @@ constexpr auto to_chars_fixed_impl(char* first, char* last, const TargetDecimalT
const auto leading_zeros {abs_exp - num_digits};
if (BOOST_DECIMAL_UNLIKELY(buffer_size < (current - first) + 2 + leading_zeros + num_digits))
{
return {last, std::errc::value_too_large}; // LCOV_EXCL_LINE
return {last, std::errc::value_too_large};
}

detail::memmove(current + 2 + leading_zeros, current, static_cast<std::size_t>(num_digits));
Expand Down
4 changes: 0 additions & 4 deletions include/boost/decimal/cstdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,8 @@ inline auto snprintf_impl(char* buffer, const std::size_t buf_size, const char*

if (!r)
{
// LCOV_EXCL_START
errno = static_cast<int>(r.ec);
return -1;
// LCOV_EXCL_STOP
}

// Adjust the capitalization and locale
Expand Down Expand Up @@ -287,7 +285,6 @@ inline auto fprintf(std::FILE* buffer, const char* format, const T... values) no
}
else
{
// LCOV_EXCL_START
// Add 50% overage in case we need to do locale conversion
std::unique_ptr<char[]> longer_char_buffer(new(std::nothrow) char[(3 * (format_len + value_space + 1)) / 2]);
if (longer_char_buffer == nullptr)
Expand All @@ -301,7 +298,6 @@ inline auto fprintf(std::FILE* buffer, const char* format, const T... values) no
{
bytes += static_cast<int>(std::fwrite(longer_char_buffer.get(), sizeof(char), static_cast<std::size_t>(bytes), buffer));
}
// LCOV_EXCL_STOP
}

return bytes;
Expand Down
10 changes: 2 additions & 8 deletions include/boost/decimal/cstdlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ inline auto strtod_calculation(const char* str, char** endptr, char* buffer, con
{
if (significand)
{
d = std::numeric_limits<TargetDecimalType>::signaling_NaN(); // LCOV_EXCL_LINE : False negative
d = std::numeric_limits<TargetDecimalType>::signaling_NaN();
}
else
{
Expand Down Expand Up @@ -125,11 +125,8 @@ inline auto strtod_impl(const char* str, char** endptr) noexcept -> TargetDecima
std::unique_ptr<char[]> buffer(new(std::nothrow) char[str_length + 1]);
if (buffer == nullptr)
{
// Hard to get coverage on memory exhaustion
// LCOV_EXCL_START
errno = ENOMEM;
return std::numeric_limits<TargetDecimalType>::quiet_NaN();
// LCOV_EXCL_STOP
}

auto d = strtod_calculation<TargetDecimalType>(str, endptr, buffer.get(), str_length);
Expand All @@ -148,7 +145,7 @@ inline auto wcstod_calculation(const wchar_t* str, wchar_t** endptr, char* buffe
if (BOOST_DECIMAL_UNLIKELY(val > 255))
{
// Character can not be converted
return std::numeric_limits<TargetDecimalType>::quiet_NaN(); // LCOV_EXCL_LINE
return std::numeric_limits<TargetDecimalType>::quiet_NaN();
}

buffer[i] = static_cast<char>(val);
Expand Down Expand Up @@ -188,11 +185,8 @@ inline auto wcstod_impl(const wchar_t* str, wchar_t** endptr) noexcept -> Target
std::unique_ptr<char[]> buffer(new(std::nothrow) char[str_length + 1]);
if (buffer == nullptr)
{
// Hard to get coverage on memory exhaustion
// LCOV_EXCL_START
errno = ENOMEM;
return std::numeric_limits<TargetDecimalType>::quiet_NaN();
// LCOV_EXCL_STOP
}

return wcstod_calculation<TargetDecimalType>(str, endptr, buffer.get(), str_length);
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/atan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ constexpr auto atan_impl(const T x) noexcept
#ifndef BOOST_DECIMAL_FAST_MATH
else if (fpc == FP_INFINITE)
{
result = my_pi_half; // LCOV_EXCL_LINE False negative
result = my_pi_half;
}
#endif
else
Expand Down
4 changes: 2 additions & 2 deletions include/boost/decimal/detail/cmath/tgamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ constexpr auto tgamma_impl(const T x) noexcept
}
else
{
result = x; // LCOV_EXCL_LINE : False negative
result = x;
}
#endif
}
else if (is_pure_int && is_neg)
{
// Pure negative integer argument.
#ifndef BOOST_DECIMAL_FAST_MATH
result = std::numeric_limits<T>::quiet_NaN(); // LCOV_EXCL_LINE : False negative
result = std::numeric_limits<T>::quiet_NaN();
#else
result = T{0};
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ constexpr auto compute_float80_128(std::int64_t q, const Unsigned_Integer &w,

if (BOOST_DECIMAL_UNLIKELY(ld == std::numeric_limits<long double>::infinity()))
{
// LCOV_EXCL_START
success = false;
ld = 0.0L;
// LCOV_EXCL_STOP
}

return ld;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/fenv_rounding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bo
if (coeff < std::numeric_limits<demoted_integer_type>::max())
{
const auto smaller_coeff {static_cast<demoted_integer_type>(coeff)};
const auto div_res {impl::divmod(smaller_coeff, static_cast<demoted_integer_type>(shift_pow_ten))}; // LCOV_EXCL_LINE : False negative since above and below are hit
const auto div_res {impl::divmod(smaller_coeff, static_cast<demoted_integer_type>(shift_pow_ten))};
shifted_coeff = static_cast<demoted_integer_type>(div_res.quotient);
const auto trailing_digits {div_res.remainder};
sticky = trailing_digits != 0U;
Expand Down
6 changes: 2 additions & 4 deletions include/boost/decimal/detail/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)

if (BOOST_DECIMAL_UNLIKELY(t_buffer_len > static_buffer_size))
{
// LCOV_EXCL_START
longer_char_buffer = std::unique_ptr<char[]>(new(std::nothrow) char[t_buffer_len]);
if (longer_char_buffer.get() == nullptr)
{
Expand All @@ -60,7 +59,6 @@ auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
}

buffer = longer_char_buffer.get();
// LCOV_EXCL_STOP
}

BOOST_DECIMAL_IF_CONSTEXPR (!std::is_same<charT, char>::value)
Expand Down Expand Up @@ -108,7 +106,7 @@ auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)

if (BOOST_DECIMAL_UNLIKELY(r.ec == std::errc::not_supported))
{
d = std::numeric_limits<DecimalType>::signaling_NaN(); // LCOV_EXCL_LINE
d = std::numeric_limits<DecimalType>::signaling_NaN();
}
else if (static_cast<int>(r.ec) == EINVAL)
{
Expand Down Expand Up @@ -166,7 +164,7 @@ auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)

if (BOOST_DECIMAL_UNLIKELY(!r))
{
errno = static_cast<int>(r.ec); // LCOV_EXCL_LINE
errno = static_cast<int>(r.ec);
}

*r.ptr = '\0';
Expand Down
8 changes: 0 additions & 8 deletions include/boost/decimal/detail/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,10 @@ constexpr auto parser(const char* first, const char* last, bool& sign, Unsigned_
const from_chars_result r {from_chars_dispatch(significand_buffer, significand_buffer + offset, significand, base)};
switch (r.ec)
{
// The two invalid cases are here for completeness, but I don't think we can actually hit them
// LCOV_EXCL_START
case std::errc::invalid_argument:
return {first, std::errc::invalid_argument};
case std::errc::result_out_of_range:
return {next, std::errc::result_out_of_range};
// LCOV_EXCL_STOP
default:
return {next, std::errc()};
}
Expand Down Expand Up @@ -372,11 +369,8 @@ constexpr auto parser(const char* first, const char* last, bool& sign, Unsigned_
const from_chars_result r {from_chars_dispatch(significand_buffer, significand_buffer + offset, significand, base)};
switch (r.ec)
{
// Out of range included for completeness, but I don't think we can actually reach it
// LCOV_EXCL_START
case std::errc::result_out_of_range:
return {next, std::errc::result_out_of_range};
// LCOV_EXCL_STOP
case std::errc::invalid_argument:
return {first, std::errc::invalid_argument};
default:
Expand Down Expand Up @@ -418,12 +412,10 @@ constexpr auto parser(const char* first, const char* last, bool& sign, Unsigned_
from_chars_result r = from_chars_dispatch(significand_buffer, significand_buffer + offset, significand, base);
switch (r.ec)
{
// LCOV_EXCL_START
case std::errc::invalid_argument:
return {first, std::errc::invalid_argument};
case std::errc::result_out_of_range:
return {next, std::errc::result_out_of_range};
// LCOV_EXCL_STOP
default:
break;
}
Expand Down
2 changes: 0 additions & 2 deletions include/boost/decimal/detail/to_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ BOOST_DECIMAL_CXX20_CONSTEXPR auto to_float(Decimal val) noexcept

if (BOOST_DECIMAL_UNLIKELY(!success))
{
// LCOV_EXCL_START
errno = EINVAL;
return 0;
// LCOV_EXCL_STOP
}

return result;
Expand Down
4 changes: 1 addition & 3 deletions include/boost/decimal/dpd_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ constexpr auto to_dpd_d128(const DecimalType val) noexcept
temp_sig /= 10U;
}
BOOST_DECIMAL_ASSERT(d[0] >= 0 && d[0] <= 9);
BOOST_DECIMAL_ASSERT(temp_sig == 0U); // LCOV_EXCL_LINE : False Negative
BOOST_DECIMAL_ASSERT(temp_sig == 0U);

constexpr std::uint64_t leading_two_exp_bits_mask {0b11000000000000};
const auto leading_two_bits {(exp & leading_two_exp_bits_mask) >> 12U};
Expand All @@ -778,14 +778,12 @@ constexpr auto to_dpd_d128(const DecimalType val) noexcept
const auto d0_is_nine {d[0] == 9};
switch (leading_two_bits)
{
// LCOV_EXCL_START
// The decimal128_t case never uses the combination field like the other types,
// since the significand always fits inside the allotted number of bits.
// I don't believe this path will ever be taken, but it's correct
case 0U:
combination_field_bits = d0_is_nine ? 0b11001 : 0b11000;
break;
// LCOV_EXCL_STOP
case 1U:
combination_field_bits = d0_is_nine ? 0b11011 : 0b11010;
break;
Expand Down