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

Fixed stream precision issue. #206

Closed
wants to merge 1 commit into from

Conversation

jdisset
Copy link

@jdisset jdisset commented Feb 10, 2016

Double->text->double or float->text->float round trip conversions were giving inexact results. Max_digits10 is the correct limit.

@nlohmann nlohmann added this to the Release 2.0.0 milestone Feb 11, 2016
@jdisset
Copy link
Author

jdisset commented Feb 11, 2016

Hi,
Sorry, I forgot to run the tests as I first made this small change for my own purposes and didn't think it would break anything. It seems some of the tests relied on what I think is an incorrect behavior:

auto s = json(42.23).dump(); CHECK(s.find("42.23") != std::string::npos);
only passes because of the rounding that was happening when using a lower precision for double->text conversions. Now, when using better precision for the decimal representation of the double we actually get "42.229999999999997".
My suggestion would be to change this test (and the other one which relies on the same behavior) and maybe rather test (with the same example values) the correct double->text->double round trip conversion instead.

Cheers and congrats for an amazing library,
Jean.

@nlohmann
Copy link
Owner

Hi @jdisset, thanks for the PR. I see that also a few roundtrip tests are failing. The input there is from miloyip/nativejson-benchmark, and there already has been a lot of discussion about floating-point numbers, see #187. It would be great if you could comment on this.

Furthermore, it would be great to have @twelsby 's opinion on this.

@nlohmann
Copy link
Owner

Hi @jdisset again. Could you please also have a look at #201? This PR may already have fixed your issue.

@nlohmann
Copy link
Owner

nlohmann commented Apr 3, 2016

This issue is fixed by PR #201.

@nlohmann nlohmann closed this Apr 3, 2016
@nlohmann nlohmann removed this from the Release 2.0.0 milestone Apr 3, 2016
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.

2 participants