File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -47,20 +47,12 @@ template <typename Out> struct Renderer
4747
4848 void operator ()(const Number &number)
4949 {
50+ // we don't want to print NaN or Infinity
51+ BOOST_ASSERT (std::isfinite (number.value ));
5052 // `fmt::memory_buffer` stores first 500 bytes in the object itself(i.e. on stack in this
5153 // case) and then grows using heap if needed
5254 fmt::memory_buffer buffer;
53- fmt::format_to (std::back_inserter (buffer), FMT_COMPILE (" {}" ), number.value );
54-
55- // Truncate to 10 decimal places
56- size_t decimalpos = std::find (buffer.begin (), buffer.end (), ' .' ) - buffer.begin ();
57- if (buffer.size () > (decimalpos + 10 ))
58- {
59- buffer.clear ();
60- fmt::format_to (std::back_inserter (buffer), FMT_COMPILE (" {0:.10f}" ), number.value );
61-
62- // buffer.resize(decimalpos + 10);
63- }
55+ fmt::format_to (std::back_inserter (buffer), FMT_COMPILE (" {:.10g}" ), number.value );
6456
6557 write (buffer.data (), buffer.size ());
6658 }
Original file line number Diff line number Diff line change @@ -27,4 +27,11 @@ BOOST_AUTO_TEST_CASE(integer)
2727 BOOST_CHECK_EQUAL (str, " 42" );
2828}
2929
30+ BOOST_AUTO_TEST_CASE (test_json_issue_6531) {
31+ std::string output;
32+ osrm::util::json::Renderer<std::string> renderer (output);
33+ renderer (0.0000000000017114087924596788 );
34+ BOOST_CHECK_EQUAL (output, " 1.711408792e-12" );
35+ }
36+
3037BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments