Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/small float serialization #38

Merged
merged 2 commits into from
Mar 23, 2015

Conversation

jrandall
Copy link
Contributor

Adds a test for small floats (which previously failed) along with a fix
for dump() that makes the test pass.

Now uses std::snprintf() to generate a "%.15g" formatted string
for JSON values of type number_float. 15 decimals digits are
enough to round-trip an IEEE 754 double from string->double->string
and get an identical result.

std::snprintf is called twice. Once to determine the required
buffer size and then again after allocating a buffer of that
size.

Note that the buffer size could be hardcoded for better
performance. "%.15g" should result in strings of maximum length
23, plus one character for the terminating null for a buffer size
of 24. Let me know if you'd like me to switch to a fixed buffer
size to avoid the extra call to snprintf and the overhead of
dynamic memory allocation.

Fixes #37

Now uses std::snprintf() to generate a "%.15g" formatted string
for JSON values of type number_float. 15 decimals digits are
enough to round-trip an IEEE 754 double from string->double->string
and get an identical result.

std::snprintf is called twice. Once to determine the required
buffer size and then again after allocating a buffer of that
size.

Note that the buffer size *could* be hardcoded for better
performance. "%.15g" should result in strings of maximum length
23, plus one character for the terminating null for a buffer size
of 24.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7bfcbe2 on wtsi-hgi:feature/small-float-serialization into 5526de1 on nlohmann:master.

@jrandall
Copy link
Contributor Author

I'm not familiar with AppVeyor, but the failure doesn't seem like it could plausibly be my fault:

'make' is not recognized as an internal or external command,
operable program or batch file.

nlohmann added a commit that referenced this pull request Mar 23, 2015
@nlohmann nlohmann merged commit a382a93 into nlohmann:master Mar 23, 2015
nlohmann added a commit that referenced this pull request Mar 23, 2015
@nlohmann
Copy link
Owner

Thanks for the pull request! I made some adjustments, because the file json.hpp is generated from json.hpp.re2c.

GerHobbelt pushed a commit to GerHobbelt/nlohmann-json that referenced this pull request May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants