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

JSON and floating point precision #72

Open
robertodr opened this issue Apr 8, 2019 · 8 comments
Open

JSON and floating point precision #72

robertodr opened this issue Apr 8, 2019 · 8 comments
Assignees
Labels
documentation Improve documentation
Milestone

Comments

@robertodr
Copy link
Contributor

I was not aware of this, but apparently reading from/writing to JSON can mess up precision of floating point numbers. I don't really know how to test and prevent this...

@bast
Copy link
Member

bast commented Apr 8, 2019

I will test this and once we have more data we can think about what we do with it.

@bast bast self-assigned this Apr 8, 2019
@bast
Copy link
Member

bast commented Apr 11, 2019

After a bit of reading (in particular https://docs.python.org/3/library/json.html#implementation-limitations), we can expect the serialized data to contain the same range and precision as the Python data types. But whether we lose the range and precision depends on who is reading the JSON.

If Python, my guess is that there is no significant loss. But with other JSON implementations, I guess it depends.

@bast
Copy link
Member

bast commented Apr 11, 2019

I also tested this locally Python -> JSON -> Python. But I haven't tested reading into another language with another implementation.

@robertodr
Copy link
Contributor Author

@stigrj can you run some tests in cpp-parselglossy? We need to check this also for the Fortran and C examples. If those JSON libraries do not present this problem, then I think we can document our preference for the JSON libraries for compiled languages and warning people about this possible pitfall with libraries we have not personally tested.

On a different note, I've never set a floating point parameter in an input file that employed the full range and precision... Any other input parser would hit the same problem, I think.

@bast
Copy link
Member

bast commented Apr 11, 2019

I also think that this is not a JSON-specific problem but basically a problem of reading a number from file. We should check how C and Fortran read floats, testing both range and precision.

@robertodr
Copy link
Contributor Author

robertodr commented Apr 11, 2019 via email

@bast
Copy link
Member

bast commented Apr 11, 2019

Where will we document our findings? On the lib side or the tutorial side?

@robertodr
Copy link
Contributor Author

A mention on both sides seems the safest bet.

@robertodr robertodr added the documentation Improve documentation label Jul 18, 2019
@robertodr robertodr added this to the v0.5.0 milestone Jul 2, 2020
@robertodr robertodr modified the milestones: v0.5.0, v1.0.0 Aug 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improve documentation
Projects
None yet
Development

No branches or pull requests

2 participants