Skip to content

fix: better edge case handling and test suite improvements#9

Merged
mootz12 merged 2 commits intomainfrom
update-math-lib
Jan 26, 2026
Merged

fix: better edge case handling and test suite improvements#9
mootz12 merged 2 commits intomainfrom
update-math-lib

Conversation

@mootz12
Copy link
Collaborator

@mootz12 mootz12 commented Jan 26, 2026

No description provided.

Copy link

Copilot AI left a comment

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 refines the core fixed-point multiplication/division helpers to handle edge cases (sign handling, overflows, and division by zero) more robustly, and significantly expands the test coverage across integer widths and Soroban U256/I256 types.

Changes:

  • Tightens mul_div_floor/mul_div_ceil implementations for u64, u128, i64, i128, U256, and I256 to use checked_* operations, correct sign-sensitive floor/ceil semantics, and safe widening fallbacks (u128/i128 and U256/I256).
  • Greatly expands and restructures test suites to cover zero, negative, overflow, “phantom overflow”, and exact/rounding scenarios for both plain and Soroban-scaled fixed-point operations.
  • Relaxes the soroban-sdk dependency constraint from 23.0.2 to the 23 major series in Cargo.toml.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/u64.rs Refactors mul_div_floor/mul_div_ceil to use u128 as a checked widening fallback with u64::try_from, and replaces legacy fixed_* tests with direct mul_div_* tests plus updated fixed_* coverage.
src/u256.rs Implements proper ceiling behavior in mul_div_ceil using remainder-based adjustment and adds comprehensive U256 tests including overflow, div-by-zero (panic) and helper for U256::MAX.
src/u128.rs Updates div_ceil to use checked_div for safer division and introduces extensive tests for mul_div_*, scaled Soroban variants, and fixed_* operations over many edge cases.
src/i64.rs Fixes sign-conditional logic in signed mul_div_floor/mul_div_ceil (true mathematical floor/ceil for negative rationals), uses i128 widening with try_from, and adds a rich matrix of signed test cases.
src/i256.rs Corrects sign handling in I256 mul_div_floor/mul_div_ceil, adds helpers for 256-bit min/max, and significantly broadens tests for positive/negative, zero, and overflow scenarios and fixed_* methods.
src/i128.rs Reimplements div_floor/div_ceil around sign-mismatch detection and checked_* ops, wires scaled Soroban variants through these helpers, and adds large, symmetric test suites for plain and Soroban fixed-point behavior; one minor comment in div_floor now mis-describes the subtraction (not the code).
Cargo.toml Adjusts the soroban-sdk dependency to the 23 major version range to align with newer SDK releases.

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mootz12 mootz12 merged commit c9233f7 into main Jan 26, 2026
3 checks passed
@mootz12 mootz12 deleted the update-math-lib branch January 26, 2026 18:43
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

Comments