-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(p/int256): changes to the int256 package implementation #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jinoosss
wants to merge
28
commits into
main
Choose a base branch
from
refactor-int256-changes-to-the-int256-package-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
refactor(p/int256): changes to the int256 package implementation #1021
jinoosss
wants to merge
28
commits into
main
from
refactor-int256-changes-to-the-int256-package-implementation
+4,002
−3,188
Conversation
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
- Add FromUint256 to convert uint256 to int256 with overflow check - Add AbsUint256 to return absolute value as uint256 - Update callers to use AbsUint256 instead of Abs where uint256 is needed
- Remove AbsUint256() function from conversion.gno - Modify Abs() in int256.gno to return *u256.Uint instead of *Int - Update all callers from AbsUint256() to Abs()
…tion, and simplify int256 tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…update router overflow tests
…he `Lsh` and `Rsh` functions
Merge all int256 package test files into two main files: - int256_test.gno: tests for int256.gno functions - conversion_test.gno: tests for conversion.gno functions Deleted files: - arithmetic_test.gno - absolute_test.gno - bitwise_test.gno - cmp_test.gno - runtime_metrics_test.gno
Remove functions that are not used externally: - Pow: power calculation - Sqrt: square root calculation - WriteToArray32: byte array conversion
…t vectors) This commit introduces a full set of division test cases derived from the Hacker’s Delight “divmnu” test vectors, adapted to the 64-bit word (256-bit Int) representation used by this package. The added tests validate the correctness of the entire udivrem() implementation, including both the 2-by-1 fast path and the full Knuth Algorithm D multi-word division path. Each test case contains: - u : dividend - v : divisor - cq : expected quotient - cr : expected remainder These vectors are intentionally constructed to exercise every edge case in Knuth’s division algorithm, not just normal divisions. The suite covers: • q̂ (quotient estimate) calculation using the top two words • q̂ over-estimation and the required decrement correction step • multiply-subtract behavior and borrow propagation across multiple words • the “add-back” correction step when subtraction underflows • normalization/unnormalization of dividend and divisor • remainder reconstruction after right-shifting • single-word divisor path (reciprocal2by1 / udivrem2by1) • boundary cases such as u < v, u == v, and very large multi-word inputs • division-by-zero behavior (panic detection) Because these test vectors originate from a mathematically verified reference implementation, they provide strong confidence that the 256-bit udivrem implementation is correct in all algorithmic branches, including those that are traditionally easy to get wrong (q̂ correction, borrow chain, signed/unsigned handling, etc.). This brings the division test coverage to a level where both correctness and algorithmic soundness are ensured without relying on big.Int or reflection.
When x is zero in uquo/urem, z.Clear() was called but execution continued to subsequent logic. Added return to exit early.
|
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.



Descriptions