Skip to content

Conversation

@jinoosss
Copy link
Member

Descriptions

notJoon and others added 11 commits November 29, 2025 10:35
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.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 1, 2025

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.

5 participants