2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00

Adding proposed fix, with tests, resolves #792 (#793)

Co-authored-by: Nana Sakisaka <1901813+saki7@users.noreply.github.com>
This commit is contained in:
sigbjorn
2025-05-09 09:43:41 +02:00
committed by GitHub
parent 0452c7b2c5
commit e6fbdf615b
2 changed files with 24 additions and 2 deletions

View File

@@ -257,8 +257,20 @@ namespace boost { namespace spirit { namespace karma
// generate(sink, right_align(precision, '0')[ulong], n);
// but it's spelled out to avoid inter-modular dependencies.
typename remove_const<T>::type digits =
(traits::test_zero(n) ? 1 : ceil(log10(n + T(1.))));
unsigned int digits=1; //should be number of digits n(truncating any fraction)
if(!boost::spirit::traits::test_zero(n)) {
static constexpr uint64_t limit = UINT64_MAX / 10;
const T num = floor(n);
for (uint64_t x = 10u, i = 1u;; x *= 10, i++) {
if (num < x) {
digits=i;break;
}
if (x > limit) {
digits= i + 1;break;
}
}
}
bool r = true;
for (/**/; r && digits < precision_; digits = digits + 1)
r = char_inserter<>::call(sink, '0');

View File

@@ -198,6 +198,16 @@ int main()
));
}
// test for #792: off by a magnitude due to fraction_part
// notice that it applies to all forms of fractions
// that end with a sequence of 0.009999
{
BOOST_TEST(test("1.09e-06",
double_,
1.09e-06
));
}
return boost::report_errors();
}