Skip to content

2025 04 15 pack#28

Merged
thedavidmeister merged 6 commits intomainfrom
2025-04-15-pack
Apr 15, 2025
Merged

2025 04 15 pack#28
thedavidmeister merged 6 commits intomainfrom
2025-04-15-pack

Conversation

@thedavidmeister
Copy link
Copy Markdown
Contributor

@thedavidmeister thedavidmeister commented Apr 15, 2025

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
    • Expanded the supported range for decimal float exponents, allowing for much larger values.
  • Bug Fixes
    • Improved handling of zero coefficients in decimal float operations.
  • Tests
    • Updated and expanded test coverage to match new coefficient and exponent ranges.
    • Added new normalization tests and adjusted test signatures for broader input support.
    • Increased test run counts and refined gas usage metrics.
  • Chores
    • Cleaned up and reorganized import statements for clarity.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2025

## Walkthrough

This set of changes expands the bit width for the signed coefficient in the decimal float packing/unpacking logic from 128 bits to 224 bits and reduces the exponent to 32 bits. The packing and unpacking functions in `LibDecimalFloat` are updated to reflect this new layout, including bitmask and shift adjustments. The exponent range constants are also updated to allow a much larger range. Test files are updated to match the new parameter types and behaviors, with some test signatures changed and a new normalization test added. Import statements are reordered or cleaned up in several test files, and minor test logic adjustments are made to align with the new internal representation.

## Changes

| File(s)                                                                                 | Change Summary                                                                                                                                                                                                                         |
|-----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| src/lib/LibDecimalFloat.sol<br>src/lib/implementation/LibDecimalFloatImplementation.sol | Increased coefficient width from 128 to 224 bits and reduced exponent to 32 bits in packing/unpacking logic; updated exponent min/max constants to use a much larger range; adjusted bitmasks and shifts accordingly.                   |
| test/src/lib/LibDecimalFloat.pack.t.sol                                                 | Updated test function parameter types to match new coefficient and exponent bit widths; changed equality assertions to use a dedicated equality function; added normalization step; adjusted logic for zero coefficients.              |
| .gas-snapshot                                                                           | Updated test metadata to reflect new test signatures, added normalization test, and recorded updated gas/time metrics for all tests.                                                                                                   |
| test/src/lib/LibDecimalFloat.divide.t.sol<br>test/src/lib/LibDecimalFloat.inv.t.sol<br>test/src/lib/LibDecimalFloat.minus.t.sol<br>test/src/lib/LibDecimalFloat.sub.t.sol | Reordered import statements for consistency; no logic changes.                                                                                                                                  |
| test/src/lib/LibDecimalFloat.multiply.t.sol                                             | Cleaned up and consolidated import statements; no functional changes.                                                                                                                           |
| test/src/lib/LibDecimalFloat.power10.t.sol                                              | Removed unused imports and deleted gas measurement code from test helper function.                                                                                                               |
| test/src/lib/parse/LibParseDecimalFloat.t.sol                                           | Added a no-op reference to a returned variable to suppress unused variable warnings.                                                                                                             |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
  participant Caller
  participant LibDecimalFloat

  Caller->>LibDecimalFloat: pack(signedCoefficient, exponent)
  alt signedCoefficient == 0
    LibDecimalFloat-->>Caller: return packed zero value
  else signedCoefficient != 0
    loop while signedCoefficient doesn't fit in 224 bits
      LibDecimalFloat->>LibDecimalFloat: signedCoefficient /= 10, exponent += 1
    end
    LibDecimalFloat->>LibDecimalFloat: check exponent fits in 32 bits
    LibDecimalFloat-->>Caller: return packed value (224-bit coeff, 32-bit exp)
  end

  Caller->>LibDecimalFloat: unpack(packedValue)
  LibDecimalFloat-->>Caller: return (signedCoefficient: 224 bits, exponent: 32 bits)

Possibly related PRs

  • mem normalize #27: Adds a normalize function and related tests, directly connected to the normalization test and signature changes in this PR.
  • float struct #24: Refactors packing/unpacking functions to use a new Float struct, related at the code level through changes in packing/unpacking logic.

Suggested reviewers

  • hardyjosh

<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbAB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6Kgk3RqdK8yJr2apqjLE9Zryyc3U0enrLYsmDWNNqvLHKdqIN9qjRMPcBTrfKDxgmy2OSgqKUVaNGbiinkrIZ7jj5XEIbmKEqwSQWq7ka3V6PeLGPT7w8mq3qCaJLOPbIA2Ey45mhEzVlmhg243Gbk2RPxqp6ObT9Z6DA/II154UPvQFH1nASDoPR5zsWr0tZOQ37XRZ3DqwuSAIvflql3W+XCtfF6AOwG83orUr11g/I3Kvp3SlIg0wBjsM92cdz6hXU7cTdgN3r21muKQKA2vehLZL2/4Jj/BoMP06hG98uKuJZfNeha9LYM6cNo6koQ0UBNAnglIHYPFSQ9ug0eEk147AObPSKvia3KKRw5FaLJQGKXCKoH0eF1xXor1C5Jh1olOSAlwvARy+g0t8iM8Zd1AXKCgdHIhaBuML2ftr2diJB8BOhuIOpIg+BLQSxuwsRq3cQS2og5vr2LpSqaOwWUa3P0aPO1VmPUTWP4XfP2qpKrIbJGJW4WI0A8BVJJ7NIWA2FdI0B9J4uVQnmTIJIc1pJLJDA5JuIDRCVOhEBCVIDww6BCVmUzK6IDBFfy5rh2trhRpMhK5rg3tsgDCGBJgkhpg3t4hrhy5y4kg0BYgBA3sGAreLfMhaAURZIGJIARoSABBDZDY0g0gBARpdk0haABAjen34gBAkhXpphQ+Rp4+BBYg0B4haAkgPfy5ZgA+IBIA0hLfphrhXfY+0hy4R4RpaBDY0BMga/4gSBMhphMgRprgGAEgGBDY3s46Zhm/5f9fA+0+VADDMh1m0By4VpDYGAU/I/4hw/DYkhC/a+3sVA8gl+w+0E9fFetJ1AVfaA1eNf9PCUlV9AgA= -->

<!-- internal state end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=rainlanguage/rain.math.float&utm_content=28):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a7ef6f and 3f80f09.

📒 Files selected for processing (14)
  • .gas-snapshot (2 hunks)
  • src/lib/LibDecimalFloat.sol (3 hunks)
  • src/lib/implementation/LibDecimalFloatImplementation.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.add.t.sol (5 hunks)
  • test/src/lib/LibDecimalFloat.divide.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.inv.t.sol (2 hunks)
  • test/src/lib/LibDecimalFloat.minus.t.sol (2 hunks)
  • test/src/lib/LibDecimalFloat.multiply.t.sol (2 hunks)
  • test/src/lib/LibDecimalFloat.normalize.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.pack.t.sol (2 hunks)
  • test/src/lib/LibDecimalFloat.power10.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.sub.t.sol (3 hunks)
  • test/src/lib/implementation/LibDecimalFloatImplementation.normalize.t.sol (2 hunks)
  • test/src/lib/parse/LibParseDecimalFloat.t.sol (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: git-clean
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
🔇 Additional comments (25)
src/lib/implementation/LibDecimalFloatImplementation.sol (1)

24-24: Expanded exponent range looks correct.

Setting EXPONENT_MAX to half of type(int256).max significantly broadens the exponent range, aligning with the design requirements for large-scale decimal arithmetic. This change appears logically consistent with the rest of the code.

test/src/lib/LibDecimalFloat.divide.t.sol (1)

5-5: Import reorder is harmless.

Reordering the import statement is a minor syntactical change that does not affect functionality. No concerns here.

test/src/lib/implementation/LibDecimalFloatImplementation.normalize.t.sol (2)

6-6: Import statement simplified to use only EXPONENT_MAX

The import statement has been modified to remove EXPONENT_MIN and only import EXPONENT_MAX, aligning with the library design change where EXPONENT_MIN is now defined as -EXPONENT_MAX.


19-19: Exponent bounding updated to use -EXPONENT_MAX

The exponent bounding has been updated to use -EXPONENT_MAX instead of EXPONENT_MIN, consistent with the import change and the updated exponent range definition in the library.

test/src/lib/LibDecimalFloat.inv.t.sol (2)

5-5: Import statement simplified to remove EXPONENT_MIN

The import statement has been modified to remove EXPONENT_MIN, keeping only LibDecimalFloat, Float, and EXPONENT_MAX, aligning with the library design change where EXPONENT_MIN is replaced by -EXPONENT_MAX.


36-36: Exponent bounding updated to use -EXPONENT_MAX

The exponent bounding has been updated to use -EXPONENT_MAX instead of EXPONENT_MIN, maintaining consistency with the import changes and the underlying library modifications.

test/src/lib/LibDecimalFloat.power10.t.sol (1)

4-4: Simplified import statement

The import statement has been modified to remove the unused EXPONENT_MIN symbol and the import of console2 from forge-std/Test.sol, which was likely only used for the removed gas measurement code. This change improves code cleanliness by removing unnecessary imports.

test/src/lib/LibDecimalFloat.minus.t.sol (2)

4-4: Import updated to remove EXPONENT_MIN

The import statement has been updated to remove EXPONENT_MIN, which aligns with the architectural change to define EXPONENT_MIN as -EXPONENT_MAX elsewhere in the codebase.


36-37: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds have been updated from using EXPONENT_MIN / 10 to using -EXPONENT_MAX / 10, which maintains the same logical behavior while adapting to the new constant structure. This change ensures symmetry around zero for the exponent range.

test/src/lib/LibDecimalFloat.sub.t.sol (3)

4-4: Import updated to remove EXPONENT_MIN

The import statement has been simplified to remove EXPONENT_MIN, which aligns with the architectural change to define EXPONENT_MIN as -EXPONENT_MAX elsewhere in the codebase.


43-44: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds have been updated from using EXPONENT_MIN / 10 to using -EXPONENT_MAX / 10, which maintains the same logical behavior while adapting to the new constant structure.


60-61: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds for the testSubMinSignedValue function have been updated to use -EXPONENT_MAX / 10 instead of EXPONENT_MIN / 10, consistent with the architectural change throughout the codebase.

test/src/lib/LibDecimalFloat.multiply.t.sol (2)

8-11: Imports reorganized for clarity

The imports have been reorganized to:

  1. Explicitly import Float and EXPONENT_MAX from LibDecimalFloat.sol
  2. Simplify the import of LibDecimalFloatImplementation by removing redundant constants

This makes the dependencies clearer and reduces import redundancy.


128-129: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds have been updated to use a symmetrical range from -EXPONENT_MAX to EXPONENT_MAX, which aligns with the architectural change to define EXPONENT_MIN as -EXPONENT_MAX.

test/src/lib/LibDecimalFloat.add.t.sol (4)

4-4: Import updated to remove EXPONENT_MIN

The import statement has been updated to remove EXPONENT_MIN, consistent with the architectural changes throughout the codebase.


116-117: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds have been updated to use -EXPONENT_MAX / 10 instead of EXPONENT_MIN / 10, which maintains the same logical behavior while adapting to the new constant structure.


130-131: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds in the testAddingSmallToLargeReturnsLargeFuzz function have been updated consistently with other bounds changes throughout the codebase.


230-231: Exponent bounds updated to use -EXPONENT_MAX

Exponent bounds in the testAddZeroToAnyNonZero function have been updated consistently with other bounds changes throughout the codebase.

.gas-snapshot (1)

1-188: Gas snapshot reflects updated parameter types and test runs.

The gas snapshot shows run counts have been updated from 5099 to 5100 for many tests, with corresponding adjustments in gas metrics. Most importantly, the snapshot reflects the parameter type changes, particularly in LibDecimalFloatPackTest functions which now use int224 for coefficients and int32 for exponents.

src/lib/LibDecimalFloat.sol (2)

26-28: Import order change for exponent constants.

The import order has been reorganized to place the exponent constants at the end of the import list.


334-339: Updated unpack function to match new bit width allocation.

The changes correctly align with the pack function:

  1. Updated bit mask to type(uint224).max
  2. Updated signextend parameter from 15 to 27 (for 224 bits)
  3. Updated right shift from 0x80 to 0xe0 (128 bits to 224 bits)

The modifications ensure proper decoding of the new packed format.

test/src/lib/LibDecimalFloat.pack.t.sol (4)

4-4: Simplified import to include only necessary constants.

The import has been streamlined to only include what's needed, improving code clarity.


26-26: Parameter type updated to match new bit allocation.

The test function's parameters now match the updated bit width allocation in the main library:

  • int224 signedCoefficient for the coefficient
  • int32 exponent for the exponent

This ensures thorough testing of the new implementation.


30-36: Improved handling of zero coefficient cases.

This change adds special handling for the zero coefficient case:

  • For non-zero coefficients, it verifies exact exponent matches
  • For zero coefficients, it ensures the exponent is normalized to zero

This is a good addition that properly tests the zero-handling behavior added to the pack function.


39-54: Enhanced round-trip test with normalization and numeric equality.

The normalized round-trip test was significantly improved:

  1. It now explicitly normalizes input values before packing
  2. Exponent range is validated before packing to avoid overflow
  3. Uses LibDecimalFloat.eq() instead of direct equality comparison

This approach ensures that round-trip conversions are tested for numeric equivalence rather than just byte-by-byte equality, which is more appropriate for floating-point values.

Comment thread src/lib/implementation/LibDecimalFloatImplementation.sol Outdated
Comment thread test/src/lib/LibDecimalFloat.normalize.t.sol Outdated
Comment thread test/src/lib/parse/LibParseDecimalFloat.t.sol
Comment thread test/src/lib/LibDecimalFloat.add.t.sol Outdated
Comment thread src/lib/LibDecimalFloat.sol
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb6644 and 4718f5a.

📒 Files selected for processing (2)
  • src/lib/LibDecimalFloat.sol (5 hunks)
  • src/lib/implementation/LibDecimalFloatImplementation.sol (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: git-clean
🔇 Additional comments (8)
src/lib/implementation/LibDecimalFloatImplementation.sol (2)

22-26: Symmetry for minimum exponent.

Defining EXPONENT_MIN as the negative of EXPONENT_MAX is straightforward and ensures consistent range boundaries. The documentation is helpful, and the implementation is clear. No issues found.


19-19:

Details

✅ Verification successful

Validate large exponent boundary.

Using type(int256).max / 2 sets a vastly large exponent boundary that dwarfs the 32-bit exponent limit enforced elsewhere. This is likely intentional for overflow checks, but please confirm the actual usage patterns to ensure no unintended consequences.

Use the following script to search for all references to EXPONENT_MAX throughout the repository and verify any assumptions behind this large boundary:


🏁 Script executed:

#!/bin/bash
rg -A 5 "EXPONENT_MAX"

Length of output: 13833


Update on EXPONENT_MAX Boundary Validation

After reviewing all references to EXPONENT_MAX across the repository, it’s clear that the design consistently uses the value defined as type(int256).max / 2 for overflow protection. Test cases in several modules (e.g., addition, subtraction, multiplication, division, and normalization) employ this constant—often scaled (like using EXPONENT_MAX / 10)—to ensure that arithmetic operations remain within safe bounds. This pattern confirms that the intentionally large exponent boundary is used only for guarding against overflows, and there are no unintended consequences observed in usage.

If the design decision to use half of the maximum int256 value as the upper bound was deliberate, then the current implementation appears sound. You may still want to double-check any external constraints (such as the referenced 32-bit limit elsewhere) to ensure that all parts of the codebase align with this approach.

src/lib/LibDecimalFloat.sol (6)

26-28: Additional imports align with expanded exponent range.

These imports for SIGNED_NORMALIZED_MAX, EXPONENT_MAX, and EXPONENT_MIN match the newly introduced constants in the implementation library. They appear consistent with the broader update to support wider exponent ranges.


286-288: Clarify packing documentation.

The updated comments rightly note that two 32-byte values (coefficient + exponent) are compressed into one 32-byte word, leading to data loss for non-normalized floats. The doc updates are accurate and improve clarity.


302-304: Short-circuit for zero coefficient.

Early returning a zero-packed float when the coefficient is zero offers a simple, efficient shortcut. This neatly sidesteps extraneous checks on the exponent.


310-313: Protecting against 32-bit exponent overflow.

This explicit check reverts when the exponent cannot fit into int32, aligning with the newly established 32-bit exponent range. It ensures correctness by guarding against out-of-bounds exponents.


315-317: Mask for storing the 224-bit coefficient.

Zeroing out the upper bits helps cleanly store negative and positive coefficients in the lower 224 bits. This approach is consistent with the sign-extension logic used during unpack.


336-340: Correct sign extension for unpack.

Using signextend(27, ...) interprets bits [223..0] of the packed word as a 224-bit signed integer, while sar(0xe0, ...) extracts the 32-bit exponent. This robustly reconstructs the original signed coefficient and exponent.

Comment thread src/lib/LibDecimalFloat.sol Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4718f5a and 8bab781.

📒 Files selected for processing (3)
  • .gas-snapshot (2 hunks)
  • src/lib/LibDecimalFloat.sol (5 hunks)
  • test/src/lib/LibDecimalFloat.divide.t.sol (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: git-clean
🔇 Additional comments (10)
test/src/lib/LibDecimalFloat.divide.t.sol (2)

5-5: Use new exponent constants import.

The updated import statement aligns with the revised exponent definitions and the new 224-bit coefficient logic.


123-124: Narrow exponent fuzzing range.

Changing the fuzz bounds to EXPONENT_MIN / 2 and EXPONENT_MAX / 2 may reduce test exploration of extreme exponents. Please confirm whether other tests still cover the full possible range or if additional test scenarios are needed.

.gas-snapshot (1)

1-4: Updated gas snapshot metrics.

All changes here appear to be updated test run counts and gas usage statistics. There are no functional code modifications. This is expected behavior after adjusting the internal float representation and exponent ranges.

Also applies to: 7-8, 12-12, 14-14, 16-16, 18-18, 21-23, 25-27, 29-29, 35-36, 37-43, 45-46, 52-52, 57-57, 63-72, 77-81, 86-90, 96-105, 107-108, 110-114, 116-117, 122-122, 129-138, 139-144, 145-150, 151-152, 155-155, 159-160, 164-164, 166-170, 171-176, 179-181, 182-183, 205-205, 213-213

src/lib/LibDecimalFloat.sol (7)

26-28: Revised references to constants.

Explicitly listing SIGNED_NORMALIZED_MAX, EXPONENT_MAX, and EXPONENT_MIN matches the new 224-bit coefficient and 32-bit exponent design.


54-55: Doc comment alignment with new bit widths.

The documentation now correctly reflects 224 signed bits for the coefficient and 32 bits for the exponent.


286-288: Clarified packing data-loss comment.

The added explanations on fitting 64 bytes into 32 bytes provide clearer insight into potential truncation during packing.


303-304: Early return for zero coefficient.

Short-circuiting when signedCoefficient == 0 is a neat optimization to avoid unnecessary processing.


318-320: Enforce exponent int32 constraint.

Reverting on exponent overflow enforces the 32-bit limit, consistent with the new design.


326-326: Bit shifting exponent into upper 32 bits.

Shifting left by 0xe0 (224 decimal) places the exponent in the top 32 bits of the packed value, aligning properly with the new layout.


343-343: Masking and sign-extending coefficient, extracting exponent.

Using a uint224 mask for the coefficient and shifting out the top 32 bits for the exponent accurately unpacks the new 224+32 format.

Also applies to: 345-346

Comment thread src/lib/LibDecimalFloat.sol
@thedavidmeister thedavidmeister merged commit 285bca7 into main Apr 15, 2025
4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Apr 18, 2025
4 tasks
This was referenced Jun 13, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2025
Merged
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 27, 2025
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Sep 16, 2025
4 tasks
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