Skip to content

feat(ff): add div_rem to BigInteger#1110

Open
pjdurden wants to merge 1 commit into
arkworks-rs:masterfrom
pjdurden:pj/biginteger-div-rem
Open

feat(ff): add div_rem to BigInteger#1110
pjdurden wants to merge 1 commit into
arkworks-rs:masterfrom
pjdurden:pj/biginteger-div-rem

Conversation

@pjdurden

@pjdurden pjdurden commented Jun 3, 2026

Copy link
Copy Markdown

Closes #645.

mul for BigInteger was added in #772, but division was still missing, so code like glv.rs still has to convert into num_bigint::BigInt to divide. This adds a div_rem to the trait that returns (quotient, remainder) for division by another BigInteger.

The implementation reuses the same base-2 long division as the existing const_modulo! helper (which only computes the remainder), extended to also accumulate the quotient bit-by-bit. No new arithmetic primitives needed.

Testing: added a randomized test that checks div_rem against num_bigint as an oracle (quotient and remainder) over 1000 random pairs for every BigInteger width, plus edge cases (0/n, n/n, dividend < divisor, division by one). Panics on division by zero, matching const_modulo!.

I left the glv.rs cleanup out of this PR to keep it focused on the primitive — happy to follow up with that (and a wide-dividend variant) if useful.

Copilot AI review requested due to automatic review settings June 3, 2026 14:38
@pjdurden pjdurden requested review from a team as code owners June 3, 2026 14:38
@pjdurden pjdurden requested review from Pratyush, WizardOfMenlo and weikengchen and removed request for a team June 3, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a div_rem API to BigInteger and implements it for BigInt<N>, with accompanying tests and release notes.

Changes:

  • Introduce BigInteger::div_rem(&self, &Self) -> (Self, Self) with docs and examples.
  • Implement base-2 long division in BigInt<N> to produce quotient and remainder.
  • Add randomized + edge-case tests using num_bigint::BigUint as an oracle, and document in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
ff/src/biginteger/mod.rs Adds the div_rem trait method and implements it for BigInt<N>.
ff/src/biginteger/tests.rs Adds property/edge-case tests for div_rem and wires them into the existing test harness.
CHANGELOG.md Notes the new div_rem API addition for ark-ff.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ff/src/biginteger/mod.rs
Comment thread ff/src/biginteger/mod.rs Outdated
Comment thread ff/src/biginteger/mod.rs Outdated
Comment thread ff/src/biginteger/tests.rs Outdated
@pjdurden pjdurden force-pushed the pj/biginteger-div-rem branch from e5881c3 to cc8800c Compare June 4, 2026 01:11
Add a div_rem method to the BigInteger trait returning the quotient and
remainder of division by another BigInteger, so callers no longer need to
detour through num_bigint::BigInt for division.

The implementation generalizes the existing const_modulo base-2 long
division to also accumulate the quotient. Tested against num_bigint as an
oracle over 1000 random pairs per BigInteger width, plus edge cases.

Closes arkworks-rs#645.
@pjdurden pjdurden force-pushed the pj/biginteger-div-rem branch from cc8800c to d25b856 Compare June 12, 2026 00:36
@pjdurden

pjdurden commented Jun 12, 2026

Copy link
Copy Markdown
Author

addressed reviews. div_rem is now a default trait method so adding it is non-breaking for existing BigInteger implementors; the isize-cast and post-move test concerns were already resolved in the latest revision, and all biginteger tests + the doctest pass. cc @Pratyush @davxy

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 multiplication and division methods for BigInteger

2 participants