1.7976931348623147e308 is serialized to 1.797693135e308, which is out of double's range
StaticJsonDocument<300> doc;
doc.set(1.7976931348623147e+308);
serializeJson(doc, std::cout); // 1.797693135e308
Online demo: https://wandbox.org/permlink/sJfBXevl6vd3KDL5
The rounding is correct, but the value is out of double
's range.
This can be an issue because when we deserialize the document, we get inf
.
One way to mitigate this issue would be to reduce the value before stringification, like so:
// prevent rounding out of double's range
if (value > 1.797693134e308)
value = 1.797693134e308
Another option would be to add some slack in the deserialization code so that it returns 1.7976931348623147e+308
instead of inf
.
I'm not sure if this issue classifies itself as a bug since the workaround can be considered a bug as well.