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
9 changes: 7 additions & 2 deletions include/boost/decimal/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
if (num_dig == precision + 1)
{
--num_dig;
exponent += fenv_round(significand);
exponent += fenv_round<TargetDecimalType>(significand);
}
}
else if (num_dig < precision && fmt != chars_format::general)
Expand Down Expand Up @@ -602,7 +602,7 @@
}

// Bounds check again
if (precision == 0)
if (precision == 0 && !append_trailing_zeros && !append_leading_zeros)
{
return {r.ptr, std::errc()};
}
Expand Down Expand Up @@ -691,6 +691,11 @@

boost::decimal::detail::memset(r.ptr, '0', zeros_inserted);
r.ptr += zeros_inserted;

if (*(r.ptr - 1) == '.')
{
--r.ptr;

Check warning on line 697 in include/boost/decimal/charconv.hpp

View check run for this annotation

Codecov / codecov/patch

include/boost/decimal/charconv.hpp#L697

Added line #L697 was not covered by tests
}
}

return {r.ptr, std::errc()};
Expand Down
19 changes: 19 additions & 0 deletions test/test_to_chars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,18 @@ void test_434_hex()
test_value(test_one_and_quarter, "7.d0000000000000000000000000000000000000000000000000p-01", chars_format::hex, 50);
}

template <typename T>
void test_777()
{
constexpr T value1 = T {21, 6, true};
constexpr T value2 = T {211, 6, true};
constexpr T value3 = T {2111, 6, true};

test_value(value1, "-21000000", chars_format::fixed, 0);
test_value(value2, "-211000000", chars_format::fixed, 0);
test_value(value3, "-2111000000", chars_format::fixed, 0);
}

int main()
{
test_non_finite_values<decimal32>();
Expand Down Expand Up @@ -853,6 +865,13 @@ int main()
test_general_format_std<decimal64>();
#endif

test_777<decimal32>();
test_777<decimal64>();
test_777<decimal128>();
test_777<decimal32_fast>();
test_777<decimal64_fast>();
test_777<decimal128_fast>();

return boost::report_errors();
}

Expand Down
Loading