Fix non-exact division in Num::U64/Num::U64 case. #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ofchecked_mul
,checked_add
, andchecked_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, sochecked_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]