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

topdown/parse_units: Use big.Rat for units parsing. #4857

Conversation

philipaconrad
Copy link
Contributor

Previously, we used big.Float for units parsing, but this resulted in occasional rounding issues, due to values like 0.001 not being perfectly representable in floating-point format.

This issue was fixed by switching units parsing to use big.Rat, since Rationals can generally handle such quantities with perfect precision.

A few new regression test cases have been added to the test suite, lifted almost verbatim from the original issue.

Fixes #4856.

@philipaconrad philipaconrad self-assigned this Jul 7, 2022
@philipaconrad philipaconrad requested review from anderseknert and removed request for ashutosh-narkar July 7, 2022 17:27
@philipaconrad philipaconrad force-pushed the issue-4856-inconsistent-units-rounding branch from 8030cb8 to 3c03733 Compare July 7, 2022 17:30
topdown/parse_units.go Outdated Show resolved Hide resolved
@philipaconrad philipaconrad force-pushed the issue-4856-inconsistent-units-rounding branch from 3c03733 to f920ac4 Compare July 7, 2022 17:40
Previously, we used big.Float for units parsing, but this resulted in
occasional rounding issues, due to values like 0.001 not being perfectly
representable in floating-point format.

This issue was fixed by switching units parsing to use big.Rat, since
Rationals can generally handle such quantities with perfect precision.

Fixes open-policy-agent#4856.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
@philipaconrad philipaconrad force-pushed the issue-4856-inconsistent-units-rounding branch from f920ac4 to 6f8279d Compare July 7, 2022 17:49
@srenatus srenatus removed the bug label Jul 7, 2022
@philipaconrad philipaconrad merged commit efab3bd into open-policy-agent:main Jul 7, 2022
@philipaconrad philipaconrad deleted the issue-4856-inconsistent-units-rounding branch September 14, 2022 20:26
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.

units.parse has inconsistent rounding errors for values of 0.5
2 participants