Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements number theory operations for BigInt2, completing PR #7 from the BigInt2 roadmap. It adds greatest common divisor (GCD), extended GCD, least common multiple (LCM), modular exponentiation, and modular inverse functionality to the BigInt2 arbitrary-precision integer type. The implementation uses efficient algorithms optimized for the base-2^32 representation and includes comprehensive test coverage.
Changes:
- Implements binary GCD (Stein's algorithm), extended GCD, LCM, modular exponentiation (mod_pow), and modular inverse (mod_inverse) in a new
number_theory.mojomodule - Adds 31 comprehensive tests covering edge cases, mathematical properties, and error conditions
- Applies performance optimization to
shrink()calls in bitwise and arithmetic operations, replacing loops with single calls when target length is known
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/decimojo/bigint2/number_theory.mojo |
New module implementing GCD (binary/Stein's algorithm), extended GCD (iterative Euclidean), LCM, modular exponentiation (binary exponentiation), and modular inverse using established number theory algorithms |
tests/bigint2/test_bigint2_number_theory.mojo |
Comprehensive test suite with 31 tests covering all number theory operations including edge cases, mathematical properties, and error handling |
src/decimojo/bigint2/arithmetics.mojo |
Performance optimization: replace loop-based shrink with single shrink call in right_shift_inplace |
src/decimojo/bigint2/bitwise.mojo |
Performance optimization: replace loop-based shrink with single shrink call in _binary_bitwise_op_inplace |
src/decimojo/bigint2/bigint2.mojo |
Add imports for bitwise and number_theory modules |
docs/readme_unreleased.md |
New comprehensive documentation file (will become README.md) with updated description emphasizing BigInt2 as the primary integer type |
docs/plans/bigint2_benchmark_analysis.md |
Update PR7 status to DONE with detailed implementation notes |
docs/plans/big_binary_integer.md |
New planning document explaining the BigInt2 design rationale and future renaming plan |
README.md |
Update description to emphasize integer types before decimal types, positioning DeciMojo as a drop-in replacement for Python's int and Decimal |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This PR implements number theory operations for BigInt2, completing Item PR7 the BigInt2 roadmap. It adds greatest common divisor (GCD), extended GCD, least common multiple (LCM), modular exponentiation, and modular inverse functionality to the BigInt2 arbitrary-precision integer type. The implementation uses efficient algorithms optimized for the base-2^32 representation and includes comprehensive test coverage.
Changes:
number_theory.mojomoduleshrink()calls in bitwise and arithmetic operations, replacing loops with single calls when target length is known