Skip to content

[integer] Polish and simplify the from_integral_scalar() method of BigInt#253

Merged
forfudan merged 2 commits into
mainfrom
dev
Jun 24, 2026
Merged

[integer] Polish and simplify the from_integral_scalar() method of BigInt#253
forfudan merged 2 commits into
mainfrom
dev

Conversation

@forfudan

@forfudan forfudan commented Jun 24, 2026

Copy link
Copy Markdown
Owner

This PR refactors BigInt.from_integral_scalar() to remove most dtype-specific branching by (1) computing the magnitude in an unsigned dtype of the same width and (2) extracting 32-bit limbs in a generic, compile-time unrolled loop. It also introduces a shared unsigned_counterpart() helper and updates the bigint enhancement plan document to describe the simplified approach.

Changes:

  • Add decimo.utility.unsigned_counterpart[dtype]() to map signed integral dtypes to their equal-width unsigned equivalents.
  • Rewrite BigInt.from_integral_scalar() to compute sign/magnitude generically and peel BITS_PER_WORD chunks in a single loop.
  • Update docs/plans/bigint_enhancement.md with notes about simplifying from_integral_scalar under limb-width parameterization.

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

This PR refactors BigInt.from_integral_scalar() to remove most dtype-specific branching by (1) computing the magnitude in an unsigned dtype of the same width and (2) extracting 32-bit limbs in a generic, compile-time unrolled loop. It also introduces a shared unsigned_counterpart() helper and updates the bigint enhancement plan document to describe the simplified approach.

Changes:

  • Add decimo.utility.unsigned_counterpart[dtype]() to map signed integral dtypes to their equal-width unsigned equivalents.
  • Rewrite BigInt.from_integral_scalar() to compute sign/magnitude generically and peel BITS_PER_WORD chunks in a single loop.
  • Update docs/plans/bigint_enhancement.md with notes about simplifying from_integral_scalar under limb-width parameterization.

Reviewed changes

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

File Description
src/decimo/utility.mojo Adds unsigned_counterpart() helper for mapping signed integral dtypes to unsigned counterparts.
src/decimo/bigint/bigint.mojo Replaces dtype-by-dtype limb extraction with a generic magnitude + peel-loop implementation.
docs/plans/bigint_enhancement.md Documents the refactor opportunity and considerations around limb-width parameterization.

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

Comment thread src/decimo/bigint/bigint.mojo
Comment thread src/decimo/bigint/bigint.mojo
Comment thread src/decimo/bigint/bigint.mojo Outdated
Comment thread src/decimo/utility.mojo
Comment thread src/decimo/bigint/bigint.mojo
@forfudan forfudan merged commit 80f9328 into main Jun 24, 2026
11 checks passed
@forfudan forfudan deleted the dev branch June 24, 2026 18:33
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.

2 participants