fix(json_render): json_render is not accurate enough for extremely sm… (#6531)
This commit is contained in:
@@ -16,7 +16,7 @@ BOOST_AUTO_TEST_CASE(number_truncating)
|
||||
|
||||
// this number would have more than 10 decimals if not truncated
|
||||
renderer(Number{42.9995999594999399299});
|
||||
BOOST_CHECK_EQUAL(str, "42.999599959");
|
||||
BOOST_CHECK_EQUAL(str, "42.99959996");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(integer)
|
||||
@@ -27,4 +27,68 @@ BOOST_AUTO_TEST_CASE(integer)
|
||||
BOOST_CHECK_EQUAL(str, "42");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_json_issue_6531)
|
||||
{
|
||||
std::string output;
|
||||
osrm::util::json::Renderer<std::string> renderer(output);
|
||||
renderer(0.0000000000017114087924596788);
|
||||
BOOST_CHECK_EQUAL(output, "1.711408792e-12");
|
||||
|
||||
output.clear();
|
||||
renderer(42.0);
|
||||
BOOST_CHECK_EQUAL(output, "42");
|
||||
|
||||
output.clear();
|
||||
renderer(42.1);
|
||||
BOOST_CHECK_EQUAL(output, "42.1");
|
||||
|
||||
output.clear();
|
||||
renderer(42.12);
|
||||
BOOST_CHECK_EQUAL(output, "42.12");
|
||||
|
||||
output.clear();
|
||||
renderer(42.123);
|
||||
BOOST_CHECK_EQUAL(output, "42.123");
|
||||
|
||||
output.clear();
|
||||
renderer(42.1234);
|
||||
BOOST_CHECK_EQUAL(output, "42.1234");
|
||||
|
||||
output.clear();
|
||||
renderer(42.12345);
|
||||
BOOST_CHECK_EQUAL(output, "42.12345");
|
||||
|
||||
output.clear();
|
||||
renderer(42.123456);
|
||||
BOOST_CHECK_EQUAL(output, "42.123456");
|
||||
|
||||
output.clear();
|
||||
renderer(42.1234567);
|
||||
BOOST_CHECK_EQUAL(output, "42.1234567");
|
||||
|
||||
output.clear();
|
||||
renderer(42.12345678);
|
||||
BOOST_CHECK_EQUAL(output, "42.12345678");
|
||||
|
||||
output.clear();
|
||||
renderer(42.123456789);
|
||||
BOOST_CHECK_EQUAL(output, "42.12345679");
|
||||
|
||||
output.clear();
|
||||
renderer(0.12345678912345);
|
||||
BOOST_CHECK_EQUAL(output, "0.1234567891");
|
||||
|
||||
output.clear();
|
||||
renderer(0.123456789);
|
||||
BOOST_CHECK_EQUAL(output, "0.123456789");
|
||||
|
||||
output.clear();
|
||||
renderer(0.12345678916);
|
||||
BOOST_CHECK_EQUAL(output, "0.1234567892");
|
||||
|
||||
output.clear();
|
||||
renderer(123456789123456789);
|
||||
BOOST_CHECK_EQUAL(output, "1.234567891e+17");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user