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

Change underlying number representation to handle large integers #154

Closed
tsandall opened this issue Nov 16, 2016 · 0 comments · Fixed by #187
Closed

Change underlying number representation to handle large integers #154

tsandall opened this issue Nov 16, 2016 · 0 comments · Fixed by #187

Comments

@tsandall
Copy link
Member

OPA currently uses float64 as the underlying number representation in storage and the AST. Float64 was used initially because this is the default return type for numbers in encoding/json. Unfortunately this leads to loss of precision when dealing with large int64 values.

One solution would be to switch to json.Number (string) as the underlying representation.

tsandall added a commit to tsandall/opa that referenced this issue Dec 5, 2016
These changes modify OPA to use json.Number to represent number values in
storage and the AST. Comparisons and numeric operations are handled by the
math/big package. Using json.Number avoids loss of precision when loading
integers greater than 2**53 and use of math/big avoids need for type
conversions in the built-in implementations. In the long run, the math/big
usage may be replaced with specific paths for smaller numbers.

Fixes open-policy-agent#154
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 a pull request may close this issue.

1 participant