fix: prettier floating point numbers

Add dragonbox to compute the required precision to print floating point
numbers. This avoids uglification of floating point numbers that
happen by default via std::stringstream.

Numbers like 34.34 used to be converted to '34.340000000000003' as strings.
With this version they will be converted to the string '34.34'.

This fixes issue https://github.com/jbeder/yaml-cpp/issues/1289
This commit is contained in:
Simon Gene Gottlieb
2024-07-06 08:00:10 +02:00
committed by Jesse Beder
parent 3d2888cc8a
commit bd070a7b76
7 changed files with 4656 additions and 4 deletions

View File

@@ -104,9 +104,11 @@ TEST_F(EmitterTest, NumberPrecision) {
out << 3.1425926f;
out << 53.5893;
out << 2384626.4338;
out << 1999926.4338;
out << 9999926.4338;
out << EndSeq;
ExpectEmit("- 3.14\n- 54\n- 2.4e+06");
ExpectEmit("- 3.14\n- 54\n- 2.4e+06\n- 2e+06\n- 1e+07");
}
TEST_F(EmitterTest, SimpleSeq) {