Skip to content

Expose abs#59

Merged
0xgleb merged 4 commits intomainfrom
feat/abs
Jun 18, 2025
Merged

Expose abs#59
0xgleb merged 4 commits intomainfrom
feat/abs

Conversation

@0xgleb
Copy link
Copy Markdown
Contributor

@0xgleb 0xgleb commented Jun 11, 2025

Motivation

We need to use Solidity Float code in Rust

Solution

Expose abs method

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

    • Introduced an absolute value calculation for floats, allowing users to obtain the non-negative value of any float.
  • Tests

    • Added tests to ensure correct behavior of the absolute value calculation, including checks for negative, positive, and zero values.

@0xgleb 0xgleb self-assigned this Jun 11, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 11, 2025

Walkthrough

A new public method, abs, was introduced to the Float struct, enabling computation of the absolute value by interacting with an EVM contract. Associated unit and property tests were added to verify correctness for various float values. No other logic or control flow outside this method and its tests were changed.

Changes

File(s) Change Summary
crates/float/src/lib.rs Added Float::abs method, which computes the absolute value via EVM call; extended tests for this method.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Float
    participant EVMContract

    Caller->>Float: abs()
    Float->>EVMContract: absCall(self)
    EVMContract-->>Float: Encoded absolute value
    Float-->>Caller: Decoded Float (absolute value)
Loading

Suggested reviewers

  • findolor
  • hardyjosh

📜 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 350525d and 5be888e.

📒 Files selected for processing (1)
  • crates/float/src/lib.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
crates/float/src/lib.rs (2)
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#59
File: crates/float/src/lib.rs:447-461
Timestamp: 2025-06-17T10:11:32.740Z
Learning: In the rainlanguage/rain.math.float repository, the user 0xgleb prefers using .unwrap() over ? in tests because it provides clearer stack traces showing the exact line where panics occurred, making debugging easier.
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#59
File: crates/float/src/lib.rs:233-242
Timestamp: 2025-06-17T10:17:56.205Z
Learning: In the rainlanguage/rain.math.float repository, the maintainer 0xgleb prefers to handle documentation additions and improvements in separate issues rather than inline with feature PRs.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)
  • GitHub Check: git-clean
🔇 Additional comments (3)
crates/float/src/lib.rs (3)

234-243: abs implementation mirrors the existing pattern – all good.

The call construction, execute_call usage, and return decoding are consistent with the other unary helpers (format, parse, etc.). No functional or stylistic issues spotted.


509-525: Unit test covers the key cases – approved.

The three-case check (negative, positive, zero) is enough to sanity-check the EVM round-trip. Naming and assertions match the maintainer’s preference of string comparison.


534-548: Property tests strengthen confidence – nice addition.

test_abs_no_minus_sign validates output invariant across a broad domain.
test_abs_abs confirms idempotence.

Both tests follow the existing style (unwrap() in tests) and hook into the existing arbitraries correctly.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@0xgleb 0xgleb linked an issue Jun 11, 2025 that may be closed by this pull request
@0xgleb 0xgleb marked this pull request as ready for review June 17, 2025 09:56
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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3fbf33a and 350525d.

📒 Files selected for processing (1)
  • crates/float/src/lib.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)

Comment thread crates/float/src/lib.rs
Comment thread crates/float/src/lib.rs
Comment thread crates/float/src/lib.rs
@0xgleb 0xgleb requested review from findolor and hardyjosh June 17, 2025 10:27
@0xgleb 0xgleb merged commit af8cd4b into main Jun 18, 2025
8 checks passed
@0xgleb 0xgleb deleted the feat/abs branch June 18, 2025 08:43
This was referenced Jun 18, 2025
This was referenced Jul 22, 2025
This was referenced Jul 29, 2025
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.

Expose abs method

3 participants