Skip to content

fix tests - #155

Merged
thedavidmeister merged 3 commits into
mainfrom
2025-10-05-example
Oct 6, 2025
Merged

fix tests#155
thedavidmeister merged 3 commits into
mainfrom
2025-10-05-example

Conversation

@thedavidmeister

@thedavidmeisterthedavidmeister commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features
    • None
  • Bug Fixes
    • Improved reliability and correctness for decimal power calculations across a wider range of inputs by enhancing overflow safeguards in interpolation.
  • Performance
    • Updated internal calibration leading to more consistent performance metrics.
  • Tests
    • Added a new test case to expand coverage for decimal power scenarios, including extreme values.
  • Chores
    • Refreshed gas/performance snapshot to reflect updated measurements and run counts.

@thedavidmeisterthedavidmeister self-assigned this Oct 6, 2025
@coderabbitai

coderabbitaiBot commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Replaces a hard-coded overflow guard in pow10 interpolation with a generic loop that rescales inputs to prevent overflow, updates the interpolation bounds accordingly, adds a new test case to cover an additional a^b scenario, and refreshes gas snapshot metrics.

Changes

Cohort / File(s)Summary
Overflow-prevention refactor in pow10 interpolation
src/lib/implementation/LibDecimalFloatImplementation.sol
Replaces special-case guard with loop that downscales scale and mantissa until idxPlus1 multiplication is safe; updates unitLinearInterpolation to use adjusted idxPlus1 * scale.
Tests for pow behavior
test/src/lib/LibDecimalFloat.pow.t.sol
Adds a new checkPow case to extend coverage for a^b.
Gas metrics refresh
.gas-snapshot
Updates recorded gas/run metrics across DecimalFloat and LibDecimalFloat tests.

Sequence Diagram(s)

sequenceDiagram
autonumber
participant C as Caller
participant L as LibDecimalFloatImplementation
participant I as Interpolation
C->>L: pow10(..., interpolation=true)
activate L
L->>L: compute idx, scale, mantissaCoefficient
Note over L: New: idxPlus1 = idx + 1
loop Rescale until safe
L->>L: while (idxPlus1 * scale) / scale != idxPlus1<br/>downscale scale and mantissaCoefficient
end
L->>I: unitLinearInterpolation(x in [idx*scale, idxPlus1*scale], ...)
activate I
I-->>L: interpolated result
deactivate I
L-->>C: result
deactivate L
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • hardyjosh

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check nameStatusExplanationResolution
Title Check❓ InconclusiveThe pull request title “fix tests” is overly generic and does not clearly convey the main changes, such as the dynamic overflow-prevention loop in pow10 interpolation and the gas snapshot updates, making it difficult to understand the core modifications at a glance.Consider updating the title to succinctly describe the primary updates, for example “Add dynamic overflow guard in pow10 interpolation and refresh gas snapshots,” so that it accurately reflects the major changes introduced in this PR.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage✅ PassedNo functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-10-05-example

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec69f1c and f89b86b.

📒 Files selected for processing (3)
  • .gas-snapshot (3 hunks)
  • src/lib/implementation/LibDecimalFloatImplementation.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.pow.t.sol (1 hunks)
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#96
File: test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol:15-29
Timestamp: 2025-08-11T14:32:50.439Z
Learning: In test code for the rain.math.float repository, redundant checks may be intentionally kept for clarity and documentation purposes, even when they could be simplified. The maintainer (thedavidmeister) prefers explicit assertions in test code to make the test's intent clear to future readers, prioritizing readability over conciseness.
📚 Learning: 2025-09-28T13:28:35.814Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#144
File: test/src/lib/LibDecimalFloat.pow.t.sol:40-61
Timestamp: 2025-09-28T13:28:35.814Z
Learning: In test/src/lib/LibDecimalFloat.pow.t.sol, the diffLimit tolerance (currently 8.6%) represents a conservative worst-case bound to accommodate precision limitations of table lookup interpolation for fractional exponents in the pow function. The exponentiation-by-squaring approach used for integer parts achieves much tighter precision, but the tolerance must account for the less precise table-based calculations used for fractional exponents.

Applied to files:

  • src/lib/implementation/LibDecimalFloatImplementation.sol
  • test/src/lib/LibDecimalFloat.pow.t.sol
  • .gas-snapshot
📚 Learning: 2025-09-30T15:09:39.446Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#144
File: src/lib/parse/LibParseDecimalFloat.sol:88-111
Timestamp: 2025-09-30T15:09:39.446Z
Learning: In src/lib/parse/LibParseDecimalFloat.sol, the fractional rescaling path (around lines 88-111) executes at most once per parseDecimalFloatInline call within an if-else branch, not in a loop, so there are no repeated 10**scale operations to optimize with a lookup table.

Applied to files:

  • src/lib/implementation/LibDecimalFloatImplementation.sol
📚 Learning: 2025-09-09T15:11:31.003Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#130
File: src/lib/implementation/LibDecimalFloatImplementation.sol:320-330
Timestamp: 2025-09-09T15:11:31.003Z
Learning: In LibDecimalFloatImplementation.sol div function, returning zero when underflowExponentBy > 76 is intentional "non-error underflow" behavior rather than reverting. This graceful handling is the main goal of the changes.

Applied to files:

  • src/lib/implementation/LibDecimalFloatImplementation.sol
📚 Learning: 2025-09-30T20:11:57.768Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#144
File: src/lib/implementation/LibDecimalFloatImplementation.sol:708-732
Timestamp: 2025-09-30T20:11:57.768Z
Learning: In src/lib/implementation/LibDecimalFloatImplementation.sol, the `lookupLogTableVal` internal function intentionally omits bounds checking for gas optimization because all calling functions perform the necessary validation before invocation (e.g., checking against LOG_MANTISSA_LAST_INDEX in log10).

Applied to files:

  • src/lib/implementation/LibDecimalFloatImplementation.sol
📚 Learning: 2025-09-28T12:52:45.815Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#144
File: src/lib/LibDecimalFloat.sol:671-686
Timestamp: 2025-09-28T12:52:45.815Z
Learning: In LibDecimalFloat.sol, the pow function has always rejected negative bases and reverted with an error. Prior to recent changes, it used a different error type, but the fundamental policy of not allowing negative bases (except when b == 0) has been consistently maintained across the codebase's history.

Applied to files:

  • src/lib/implementation/LibDecimalFloatImplementation.sol
📚 Learning: 2025-09-10T19:20:35.927Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#135
File: test/src/lib/LibDecimalFloat.pow.t.sol:160-161
Timestamp: 2025-09-10T19:20:35.927Z
Learning: In test/src/lib/LibDecimalFloat.pow.t.sol, the comment "we do not try" in the context of "The round trip should not error so we do not try" refers to not using try/catch constructs around the powExternal call, contrasting with previous versions that used nested try/catch blocks.

Applied to files:

  • test/src/lib/LibDecimalFloat.pow.t.sol
📚 Learning: 2025-08-21T18:03:40.347Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#107
File: test/lib/LibDecimalFloatSlow.sol:37-45
Timestamp: 2025-08-21T18:03:40.347Z
Learning: In test/lib/LibDecimalFloatSlow.sol, the "slow" implementation is intentionally different from the production implementation to serve as an independent reference for fuzzing tests. The goal is to have two different approaches (expensive loops vs optimized jumps) that produce equivalent results, not identical implementations.

Applied to files:

  • .gas-snapshot
📚 Learning: 2025-08-29T14:54:24.240Z
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#115
File: test/src/lib/LibDecimalFloat.decimal.t.sol:122-126
Timestamp: 2025-08-29T14:54:24.240Z
Learning: In test/src/lib/LibDecimalFloat.decimal.t.sol, the fromFixedDecimalLossy function converts uint256(type(int256).max) losslessly because the boundary check is `value > uint256(type(int256).max)`, not `>=`. Values exactly equal to type(int256).max still take the lossless conversion path.

Applied to files:

  • .gas-snapshot
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: git-clean
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-legal)

Comment @coderabbitai help to get the list of available commands and usage tips.

@thedavidmeister
thedavidmeister merged commit fd29fea into mainOct 6, 2025
10 checks passed
@github-actions

Copy link
Copy Markdown

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

@coderabbitai

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

SIZE=M


🧠 Learnings used
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#96
File: test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol:15-29
Timestamp: 2025-08-11T14:32:50.439Z
Learning: In test code for the rain.math.float repository, redundant checks may be intentionally kept for clarity and documentation purposes, even when they could be simplified. The maintainer (thedavidmeister) prefers explicit assertions in test code to make the test's intent clear to future readers, prioritizing readability over conciseness.

@coderabbitaicoderabbitaiBot mentioned this pull request Oct 21, 2025
4 tasks
@coderabbitaicoderabbitaiBot mentioned this pull request Jan 29, 2026
4 tasks
Sign up for freeto 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

@thedavidmeister