Make double
roundtrip when serializing and deserializing to JSON
#285
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current develop branch of cereal has several problems with serialization and deserialization of
double
values:1e-20
is serialized as0.0
. The setting to avoid truncation is given byrapidjson::Writer<>::kDefaultMaxDecimalPlaces
and is equal to 324 decimal placed (not 17). I think you may have misunderstood theSetMaxDecimalPlaces()
option of the current rapidjson writer.nan
,inf
and-inf
are not serialized by the current version of rapidjson (nothing is printed at all, resulting in an invalid json representation that cannot be deserialized, i.e., crashes on deserialization).rapidjson::kParseFullPrecisionFlag
), the deserialization loses up to 3 bits of precision. For example, deserializing0.9868011474609375
becomes0.9868011474609376
.This pull request presents a possible fix to all of these issues (1 and 3 being rather trivial changes to json.hpp)
By the way, note that the version of rapidjson you currently include in the develop branch is not 1.0.2, but a rather recent version from the master branch.