rpp::string_buffer::write(double) keeps 6 decimals and never uses scientific notation, so a
value that needs more precision is written wrong and the caller gets no warning.
_tostring(char* buffer, double value, int maxDecimals = 6) in rpp/strview.h sets that
limit. The limit is not reachable from string_buffer, because write(double) takes no
precision parameter.
rpp::string_buffer sb;
sb.write(59.43696123456789); // -> "59.436961" 6 decimals, the rest is gone
sb.write(1e-9); // -> "0.000000" the value is lost
sb.write(1e300); // no scientific notation
This is easy to walk into. A GPS latitude written through string_buffer loses about 1 cm of
resolution per lost decimal, and the text still looks correct.
Suggested fix
Add an overload that passes the precision through, the same way _tostring already accepts
it:
string_buffer& write(double value, int maxDecimals);
A shortest round-trip form would be better still, so write(double) returns text that parses
back to the same value. std::to_chars(first, last, value) gives that.
Found while replacing a JSON serializer in a downstream project. We had to use Qt for the
double output, because string_buffer could not write the settings file correctly.
rpp::string_buffer::write(double)keeps 6 decimals and never uses scientific notation, so avalue that needs more precision is written wrong and the caller gets no warning.
_tostring(char* buffer, double value, int maxDecimals = 6)inrpp/strview.hsets thatlimit. The limit is not reachable from
string_buffer, becausewrite(double)takes noprecision parameter.
This is easy to walk into. A GPS latitude written through
string_bufferloses about 1 cm ofresolution per lost decimal, and the text still looks correct.
Suggested fix
Add an overload that passes the precision through, the same way
_tostringalready acceptsit:
A shortest round-trip form would be better still, so
write(double)returns text that parsesback to the same value.
std::to_chars(first, last, value)gives that.Found while replacing a JSON serializer in a downstream project. We had to use Qt for the
double output, because
string_buffercould not write the settings file correctly.