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

Fix non-exact division in Num::U64/Num::U64 case. #51

Merged
merged 1 commit into from
Mar 14, 2022
Merged

Conversation

porcuquine
Copy link
Collaborator

@porcuquine porcuquine commented Mar 14, 2022

There was a bug in the division implementation. Specifically, the previous code used checked_div on the assumption that this would catch cases in which we need to promote to Scalar / Scalar division. Presumably, this was an extrapolation from the similar uses of checked_mul, checked_add, and checked_sub. Those are all actually correct, but since U64 is not a field, normal division only gives correct results when exact. We never want, truncating integer division, so checked_div is not a strong enough check.

This PR fixes that, with a minimal change to the test to demonstrate the need.

We should create much more thorough tests over ranges of values in combinations which will exercise this behavior. In particular, we should include algebraic identities which must always hold. (This will be useful for later property checking and/or fuzz testing.) I will create a separate issue for that. [Update: #52]

dignifiedquire
dignifiedquire previously approved these changes Mar 14, 2022
Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

emmorais
emmorais previously approved these changes Mar 14, 2022
Base automatically changed from opaque-data to master March 14, 2022 16:23
@porcuquine porcuquine dismissed stale reviews from emmorais and dignifiedquire via ff26dfc March 14, 2022 16:29
@porcuquine porcuquine merged commit c64c98b into master Mar 14, 2022
@porcuquine porcuquine deleted the bugfix-div branch March 14, 2022 18:08
emmorais pushed a commit that referenced this pull request Mar 14, 2022
Co-authored-by: porcuquine <porcuquine@users.noreply.github.com>
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.

None yet

3 participants