Skip to content

feat: add mod, a floored remainder that never follows a negative dividend - #55

Closed
VedantMadane wants to merge 1 commit into
Stiven-Gjekaj:mainfrom
VedantMadane:feat/issue-44-mod-floored
Closed

VedantMadane wants to merge 1 commit into
Stiven-Gjekaj:mainfrom
VedantMadane:feat/issue-44-mod-floored

Conversation

@VedantMadane

Copy link
Copy Markdown
Contributor

Summary

% truncates toward zero (-7 % 3 is -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

  • New builtin mod(n, d): floored remainder; sign follows the divisor.
  • Zero divisor refuses with the same "modulo by zero" words as %.
  • Integers stay integers; any float promotes, matching other binary numeric builtins.
  • Spec section 8.7 documents mod and how it differs from %.
  • Unit tests cover positive/negative divisors, floats, zero, and type errors.
  • Builtin registry counts updated so the pinned-list guards stay honest.

Test plan

  • cargo test --lib mod_
  • cargo test --lib the_pinned_list
  • cargo test --lib builtin_kind_counts

Fixes #44

…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>
@VedantMadane

VedantMadane commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #54 (same mod builtin).

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.

Add mod, a remainder that is never negative

1 participant