Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe UD30x9 fixed-point math implementation now includes bounds checks in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #201 +/- ##
==========================================
+ Coverage 95.58% 95.60% +0.01%
==========================================
Files 19 19
Lines 1541 1548 +7
Branches 389 394 +5
==========================================
+ Hits 1473 1480 +7
Misses 48 48
Partials 20 20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
math/fixed_point/sources/ud30x9/ud30x9_base.move (1)
86-87: Document the newbits >= 128 => 0behavior in function docs.The implementation changed semantics at the boundary; the doc comments should state this explicitly to avoid API ambiguity.
Proposed doc update
-/// Implements the left shift operation (<<) for `UD30x9` type. +/// Implements the left shift operation (<<) for `UD30x9` type. +/// Returns zero when `bits >= 128`. public fun lshift(x: UD30x9, bits: u8): UD30x9 { @@ -/// Implements the right shift operation (>>) for `UD30x9` type. +/// Implements the right shift operation (>>) for `UD30x9` type. +/// Returns zero when `bits >= 128`. public fun rshift(x: UD30x9, bits: u8): UD30x9 {Also applies to: 158-159
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@math/fixed_point/sources/ud30x9/ud30x9_base.move` around lines 86 - 87, The function docs for lshift (and the analogous right-shift function at the same region) must explicitly state the new boundary behavior: when the shift amount bits is >= 128 the result is defined to be 0; update the doc comment above public fun lshift(x: UD30x9, bits: u8): UD30x9 to mention "bits >= 128 => 0" and add the same clarifying sentence to the doc comment for the corresponding rshift function (the other shift function at lines ~158-159) so callers are aware of the changed semantics and the exact behavior at the boundary.math/fixed_point/tests/ud30x9_tests.move (1)
122-144: Addbits = 127boundary tests to guard off-by-one regressions.You now assert saturation at and above 128; adding explicit 127 checks would lock down the threshold behavior.
Suggested test additions
+#[test] +fun lshift_by_127_keeps_shift_semantics() { + let x = fixed(1); + expect(x.lshift(127), fixed(1u128 << 127)); +} + +#[test] +fun rshift_by_127_keeps_shift_semantics() { + let x = fixed(MAX_VALUE); + expect(x.rshift(127), fixed(1)); +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@math/fixed_point/tests/ud30x9_tests.move` around lines 122 - 144, Add two boundary tests for the 127-bit case to prevent off-by-one regressions: in math/fixed_point/tests/ud30x9_tests.move add a lshift_by_127_not_zero test and a rshift_by_127_not_zero test that use let x = fixed(1) and call x.lshift(127) and x.rshift(127) respectively, asserting the results are not equal to fixed(0) (i.e., expect non-zero) so the threshold at 128 is explicitly verified; place them alongside the existing lshift_by_128_returns_zero and rshift_by_128_returns_zero tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@math/fixed_point/sources/ud30x9/ud30x9_base.move`:
- Around line 86-87: The function docs for lshift (and the analogous right-shift
function at the same region) must explicitly state the new boundary behavior:
when the shift amount bits is >= 128 the result is defined to be 0; update the
doc comment above public fun lshift(x: UD30x9, bits: u8): UD30x9 to mention
"bits >= 128 => 0" and add the same clarifying sentence to the doc comment for
the corresponding rshift function (the other shift function at lines ~158-159)
so callers are aware of the changed semantics and the exact behavior at the
boundary.
In `@math/fixed_point/tests/ud30x9_tests.move`:
- Around line 122-144: Add two boundary tests for the 127-bit case to prevent
off-by-one regressions: in math/fixed_point/tests/ud30x9_tests.move add a
lshift_by_127_not_zero test and a rshift_by_127_not_zero test that use let x =
fixed(1) and call x.lshift(127) and x.rshift(127) respectively, asserting the
results are not equal to fixed(0) (i.e., expect non-zero) so the threshold at
128 is explicitly verified; place them alongside the existing
lshift_by_128_returns_zero and rshift_by_128_returns_zero tests.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
math/fixed_point/sources/ud30x9/ud30x9_base.movemath/fixed_point/tests/ud30x9_tests.move
immrsd
left a comment
There was a problem hiding this comment.
LGTM! Slightly improved the doc to be more informative and consistent with SD29x9 docs
Resolves #165
Summary by CodeRabbit
Bug Fixes
Tests