feat: add mod, a floored remainder that never follows a negative dividend - #55
Closed
VedantMadane wants to merge 1 commit into
Closed
VedantMadane wants to merge 1 commit into
VedantMadane wants to merge 1 commit into
Conversation
…dend % truncates toward zero, so wrapping arithmetic needs ((n % d) + d) % d. mod(n, d) is the floored form: sign follows the divisor, zero divisor refuses with the same words as %, and floats promote like every other binary numeric builtin. Fixes Stiven-Gjekaj#44 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Contributor
Author
|
Closing as duplicate of #54 (same mod builtin). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
%truncates toward zero (-7 % 3is-1), which is the right division remainder but the wrong answer for wrapping. Every ring buffer / clock / hash-bucket use ends up written as((n % d) + d) % d.Change
mod(n, d): floored remainder; sign follows the divisor.%.modand how it differs from%.Test plan
cargo test --lib mod_cargo test --lib the_pinned_listcargo test --lib builtin_kind_countsFixes #44