Skip to content

feat: add math/base/special/tanhf - #14829

Open
AryanSharma48 wants to merge 6 commits into
stdlib-js:developfrom
AryanSharma48:feat-add-tanhf
Open

feat: add math/base/special/tanhf#14829
AryanSharma48 wants to merge 6 commits into
stdlib-js:developfrom
AryanSharma48:feat-add-tanhf

Conversation

@AryanSharma48

@AryanSharma48 AryanSharma48 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Resolves a part of #649 .

Description

What is the purpose of this pull request?

This pull request:

  • introduces the @stdlib/math/base/special/tanhf package, which computes the hyperbolic tangent of a single-precision floating-point number.
  • creates the standard package structure including JS implementations, Native C addons (addon.c, main.c), Type definitions, Benchmarks, and Tests.
  • generates comprehensive test fixtures using pure Python to test edge cases, small values, and large values.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

I consulted an AI assistant to help me research and understand the stdlib native package structure, specifically how to navigate C addons, bindings, and directory requirements by studying existing packages like tanf, sinhf and coshf.


@stdlib-js/reviewers

Signed-off-by: Aryan Sharma <aryansharma24106@gmail.com>
@stdlib-bot stdlib-bot added the Math Issue or pull request specific to math functionality. label Aug 30, 2026
@stdlib-bot

stdlib-bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/tanhf $\\color{green}267/267$
$\\color{green}+0.71\\%$
$\\color{green}19/19$
$\\color{green}+5.26\\%$
$\\color{green}3/3$
$\\color{green}+0.00\\%$
$\\color{green}267/267$
$\\color{green}+0.71\\%$

The above coverage report was generated for the changes in this PR.

Signed-off-by: Aryan Sharma <aryansharma24106@gmail.com>
Signed-off-by: Aryan Sharma <aryansharma24106@gmail.com>
Signed-off-by: Aryan Sharma <aryansharma24106@gmail.com>
@AryanSharma48
AryanSharma48 marked this pull request as ready for review August 30, 2026 21:29
@AryanSharma48
AryanSharma48 requested a review from a team August 30, 2026 21:29
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 30, 2026
@AryanSharma48

Copy link
Copy Markdown
Contributor Author

Hey @kgryte! The coverage is at 282/284 statements and 19/20 branches. The only missing coverage is the if ( tanhf instanceof Error ) fallback in lib/index.js, because the C add-on successfully compiled in CI and didn't fall back to pure JS. Everything else is at 100%.

Also, while referencing @stdlib/math/base/special/sinhf, I noticed its lib/index.js completely lacks a tryRequire dispatcher and only exports main.js, which means its C add-on is completely disconnected. Just wanted to flag that oversight!

@kgryte

kgryte commented Aug 30, 2026

Copy link
Copy Markdown
Member

You should not be exporting the native add-on. What sinhf does is intentional. See the other packages in math/base/special. It doesn't make sense to defer to the native add-on for a scalar kernel. The perf penalty for evaluating a single scalar is too prohibitive when crossing from JS to C.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Aug 30, 2026
@kgryte

kgryte commented Aug 30, 2026

Copy link
Copy Markdown
Member

Also, isn't this PR a duplicate of #10498?

@AryanSharma48

AryanSharma48 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

For the duplicate problem, #10498 was stalled as it was marked as duplicate as there was originally #10217 addressing this, but that got closed, hence i opened this one.

Let me know if I should keep the work continue on this and until then ill start working on the issue of exporting native add-on, and push the fix for that!

Signed-off-by: Aryan Sharma <aryansharma24106@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Math Issue or pull request specific to math functionality. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants