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

Print float values with full precision. #3480

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phile314
Copy link

@phile314 phile314 commented Apr 9, 2020

Instead of printing at most 6 digits, print as many digits as are
necessary to preserve float values exactly.

I did run into this when building a config file using nix which has float values requiring at least seven significant digits. With this PR the values are sometimes less pretty, but it is less surprising and makes the float values more versatile.

See also http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf

This max_digits10 number is also the number of decimal digits required to avoid loss of accuracy when converting to a string and back to a floating-point representation, for example during serialization.

Instead of printing at most 6 digits, print as many digits as are
necessary to preserve float values exactly.

See also http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf
@edolstra
Copy link
Member

edolstra commented Apr 9, 2020

It's important to note that this change causes evaluation results to diverge between different versions of Nix. But maybe we shouldn't care because few people use floating point anyway.

@phile314
Copy link
Author

Is there anything I can do to help getting this merged?

@phile314
Copy link
Author

phile314 commented Aug 4, 2020

Ping

@phile314
Copy link
Author

phile314 commented Feb 4, 2021

Any news?

@stale
Copy link

stale bot commented Aug 4, 2021

I marked this as stale due to inactivity. → More info

@infinisil
Copy link
Member

There is a PR related to this #6238, though it's kind of blocked on a solution like NixOS/rfcs#137

@stale stale bot removed the stale label Mar 10, 2023
@Ericson2314
Copy link
Member

Ericson2314 commented May 13, 2023

See also #8259: we accidentally made float printing in JSON more precise. I will mention this PR in that issue.

@Ericson2314
Copy link
Member

Marking draft because this is old and there are conflicts.

@Ericson2314 Ericson2314 marked this pull request as draft May 13, 2023 13:09
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.

4 participants