Skip to content

perf(rational): compare without overflow or BigInt allocation - #292

Open
kokic wants to merge 2 commits into
mainfrom
perf-rational-compare
Open

perf(rational): compare without overflow or BigInt allocation#292
kokic wants to merge 2 commits into
mainfrom
perf-rational-compare

Conversation

@kokic

@kokic kokic commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Improves @rational comparison for fixed-width integer values: cross-multiplication stays in fixed-width arithmetic when safe, falling back to a continued-fraction algorithm only when the product would overflow, avoiding BigInt allocation entirely.

Changes

  • Add compare_fraction to the Integral trait with Int64, Int, and BigInt implementations
  • Move the Compare impl into rational/compare.mbt
  • Relocate inline tests into rational_wbtest.mbt
  • Add boundary-value tests and an exhaustive int64-vs-bigint parity check

Closes #291 overflow concern; includes the changelog entry for the fix.

kokic added 2 commits August 5, 2026 15:53
Introduce a compare_fraction method on the Integral trait so Rational
comparison can use fixed-width cross-products when they fit, with a
continued-fraction fallback for Int64 products that would overflow.
Move the Compare impl into rational/compare.mbt and relocate the old
inline tests into rational_wbtest.mbt, adding boundary-value tests and
an exhaustive int64-vs-bigint parity check.
@kokic
kokic requested a review from myfreess August 5, 2026 08:51
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.

1 participant