Skip to content

Comments

feat: add tanh (hyperbolic tangent) library#12

Open
coffeexcoin wants to merge 1 commit intomainfrom
tanh
Open

feat: add tanh (hyperbolic tangent) library#12
coffeexcoin wants to merge 1 commit intomainfrom
tanh

Conversation

@coffeexcoin
Copy link
Contributor

@coffeexcoin coffeexcoin commented Jan 30, 2026

PR-Codex overview

This PR introduces a new library, LibTanh, for calculating the hyperbolic tangent of a number in Solidity, along with a set of tests in LibTanhTest to verify its functionality and handle overflow cases.

Detailed summary

  • Added LibTanh library with functions tanh and rawTanh.
  • Implemented private function _tanh for internal calculations.
  • Introduced error handling for overflow with TanhOverflow.
  • Created LibTanhTest contract with multiple test cases for tanh.
  • Added tests for overflow scenarios and expected results for various inputs.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@cursor
Copy link

cursor bot commented Jan 30, 2026

PR Summary

Medium Risk
Introduces new fixed-point math based on expWad with explicit overflow behavior; mistakes here could affect any downstream financial calculations that rely on tanh outputs.

Overview
Adds LibTanh, a WAD-scaled hyperbolic tangent implementation using FixedPointMathLib.expWad, with two entrypoints: tanh (reverts with TanhOverflow) and rawTanh (saturates to 1e18 on overflow).

Adds LibTanh.t.sol test coverage for expected outputs across several inputs and verifies both revert-on-overflow and saturation behavior.

Written by Cursor Bugbot for commit 56d2c48. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
import {console2} from "forge-std/console2.sol";
Copy link

Choose a reason for hiding this comment

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

Debug import left in production library code

Low Severity

The console2 import from forge-std is a debugging/testing utility that was left in the production library code. It's imported but never actually used in the library. The forge-std package is a testing framework dependency and this import doesn't belong in production smart contract code.

Fix in Cursor Fix in Web

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