forked from open-policy-agent/opa
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topdown/parse_units: Use big.Rat for units parsing.
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>
- Loading branch information
1 parent
cfa5c6e
commit 6f8279d
Showing
2 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cases: | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("500m") == 0.5 | ||
} | ||
note: units_parse/exact comparison - regression case 1 | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- | | ||
package test | ||
p { | ||
units.parse("0.0005K") == 0.5 | ||
} | ||
note: units_parse/exact comparison - regression case 2 | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- | | ||
package test | ||
p { | ||
units.parse("0.0000005M") == 0.5 | ||
} | ||
note: units_parse/exact comparison - regression case 3 | ||
query: data.test.p = x | ||
want_result: | ||
- x: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters