Sitelet https://github.com/starkware-libs/cairo/pull/10027
Skip to content

fix(corelib): add /= and %= for i32/i64/i128 via non-deprecated *Assign - #10027

Merged
orizi merged 1 commit into
mainfrom
orizi/signed-int-div-rem-assign
Jun 2, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/signed-int-div-rem-assign

Conversation

@orizi

@orizi orizi commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds DivAssign (/=) and RemAssign (%=) implementations for i32, i64, and i128 signed integer types, which were previously missing. A new op_assign_by_op module is introduced to derive these assignment operators from their corresponding binary operators (Div and Rem), mirroring the existing op_eq_by_op pattern.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

i8 and i16 had /= and %= operators, but i32, i64, and i128 did not, creating an inconsistency across signed integer types.


What was the behavior or documentation before?

Using /= or %= on i32, i64, or i128 values was not supported, while the same operators worked on i8 and i16.


What is the behavior or documentation after?

/= and %= are now supported uniformly across all signed integer types (i8, i16, i32, i64, i128). Tests cover division and remainder assignment for positive and negative values across all three newly supported types.


Related issue or discussion (if any)

N/A


Additional context

The new op_assign_by_op module is intentionally kept separate from the existing op_eq_by_op module to avoid using deprecated traits.

i32/i64/i128 lacked DivAssign/RemAssign (only i8/i16 had the deprecated
DivEq/RemEq that bridge to them). Add a non-deprecated `op_assign_by_op`
helper deriving DivAssign/RemAssign from the binary Div/Rem ops, and
instantiate it for i32/i64/i128. Add a regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi requested a review from eytan-starkware June 2, 2026 07:21
@orizi
orizi marked this pull request as ready for review June 2, 2026 07:21
@cursor

cursor Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Small corelib consistency fix reusing existing Div/Rem semantics; no new division algorithms or API surface beyond missing operators.

Overview
Adds /= and %= for signed i32, i64, and i128, which previously could not use those assignment operators while smaller signed types could.

A new op_assign_by_op module implements non-deprecated DivAssign and RemAssign by delegating to existing Div / Rem (same idea as op_eq_by_op, but without deprecated traits). integer_test gains test_signed_div_rem_assign covering positive and negative division and remainder updates on all three widths.

Reviewed by Cursor Bugbot for commit 25db239. Bugbot is set up for automated code reviews on this repo. Configure here.

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).


corelib/src/integer.cairo line 2662 at r1 (raw file):

impl I16AddEq = op_eq_by_op::AddEqImpl<i16>;
impl I16SubEq = op_eq_by_op::SubEqImpl<i16>;
impl I16MulEq = op_eq_by_op::MulEqImpl<i16>;

Consider also changing diveq to divassign in i8 and i16

@orizi
orizi added this pull request to the merge queue Jun 2, 2026
Merged via the queue into main with commit 9656ddd Jun 2, 2026
54 checks passed
@orizi
orizi deleted the orizi/signed-int-div-rem-assign branch June 3, 2026 07:13
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.

3 participants