Skip to content

Power function for float raised by float - #693

Merged
ozgunozerk merged 6 commits into
mainfrom
float-pow
May 13, 2026
Merged

ozgunozerk merged 6 commits into
mainfrom
float-pow

Conversation

@ozgunozerk

@ozgunozerk ozgunozerk commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #692

PR Checklist

  • Tests
  • Documentation

Summary by CodeRabbit

  • New Features

    • Added natural logarithm (ln) and exponential (exp) mathematical functions
    • Introduced fractional power exponentiation (powf) to raise values to non-integer exponents
    • Integer power operations renamed from pow to powi for naming clarity
    • Added checked variants for safe error handling of ln, exp, and powf operations
  • Error Handling

    • Improved validation for mathematical operations with invalid inputs

@ozgunozerk
ozgunozerk requested a review from brozorec May 8, 2026 15:07
@ozgunozerk ozgunozerk self-assigned this May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50ca6ab8-8cf7-458c-a3b8-246080a06853

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR introduces transcendental math functions (ln and exp) for the 18-decimal fixed-point Wad type using Solmate-derived Padé approximations. It renames integer exponentiation from pow/checked_pow to powi/checked_powi, and provides a floating-point power function (powf/checked_powf) that computes exp(exponent × ln(self)). Comprehensive tests validate all new operations and edge cases.

Changes

Transcendental Math Functions and Floating-Point Power

Layer / File(s) Summary
Error Domain & Module Integration
packages/contract-utils/src/math/mod.rs
Added exp_ln module declaration and InvalidBase error variant (1502) for domain violations in ln and powf with non-positive bases.
Low-Level Transcendental Implementations
packages/contract-utils/src/math/exp_ln.rs
Implements ln_wad (range-reduced via ilog2, Padé approximation in I256) and exp_wad (range reduction via ln(2), rational approximation, U256 scaling) with Option<i128> return types for overflow/underflow safety.
Public API Imports
packages/contract-utils/src/math/wad.rs
Updated imports to expose exp_wad and ln_wad for use in public Wad methods.
Integer Exponentiation Refactoring
packages/contract-utils/src/math/wad.rs
Renamed pow/checked_pow to powi/checked_powi to clarify integer-exponent semantics; logic and overflow handling via checked fixed-point multiplication unchanged.
Transcendental & Fractional Power API
packages/contract-utils/src/math/wad.rs
Added ln, checked_ln, exp, checked_exp, powf, and checked_powf methods. powf includes special-case fast paths for 0^0, 0^y, 1^y, x^1, and delegates to powi for integer exponents; general case computes exp(exponent × ln(self)).
Integer Exponentiation Tests
packages/contract-utils/src/math/test/wad.rs
Expanded powi and checked_powi test coverage with identity/edge cases (zero, one), fractional bases, negative bases, precision/truncation behavior, and overflow panic detection.
Transcendental & Power Function Tests
packages/contract-utils/src/math/test/wad.rs
New test suites for ln/checked_ln (domain validation, known values, panic/None behavior), exp/checked_exp (roundtrip exp(ln(x)), underflow/overflow bounds), and powf/checked_powf (edge cases, integer fast-path equivalence, tolerance-based fractional exponentiation checks) with shared assert_close helper for numerical tolerance.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 With logs and exponentials now in hand,
Our fixed-point Wad can take a power stand,
From simple powi to fractional powf,
The transcendental math makes hearts aloof!
With rational Padé to guide the way,
We calculate with WAD-scaled display! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the main feature addition: a power function for float raised by float, matching the primary change in the PR.
Description check ✅ Passed The PR description references the linked issue (#692) and confirms that Tests and Documentation checklist items are completed, though details about implementation are minimal.
Linked Issues check ✅ Passed The PR successfully implements the core objective from issue #692: a power function for float raised by float via new powf/checked_powf methods supporting Wad-to-Wad exponentiation.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing float-to-float power functionality: new ln_wad and exp_wad functions enable the computation of powf, test coverage is comprehensive, and integer-power methods are appropriately renamed for clarity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch float-pow

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@codecov

codecov Bot commented May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.76543% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.30%. Comparing base (c5c86c4) to head (afae44e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/contract-utils/src/math/wad.rs 97.36% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #693      +/-   ##
==========================================
+ Coverage   96.24%   96.30%   +0.06%     
==========================================
  Files          59       60       +1     
  Lines        6206     6365     +159     
==========================================
+ Hits         5973     6130     +157     
- Misses        233      235       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brozorec brozorec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Everything looks sound, just couple of nitpicks. Would it be possible to further improve the coverage?

Comment thread packages/contract-utils/src/math/wad.rs Resolved
@ozgunozerk
ozgunozerk merged commit dc15737 into main May 13, 2026
8 checks passed
@ozgunozerk
ozgunozerk deleted the float-pow branch May 13, 2026 05:49
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2026
2 tasks done
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.

🏗️ [Core Feature]: Float raised by float

2 participants