Skip to content

feat: add math/base/special/cschf - #16583

Open
devxsubh wants to merge 2 commits into
stdlib-js:developfrom
devxsubh:feat/math-base-special-cschf
Open

devxsubh wants to merge 2 commits into
stdlib-js:developfrom
devxsubh:feat/math-base-special-cschf

Conversation

@devxsubh

Copy link
Copy Markdown
Contributor

Resolves a part of #649.

Description

What is the purpose of this pull request?

This pull request:

  • adds @stdlib/math/base/special/cschf, which computes the hyperbolic cosecant of a single-precision floating-point number, with JavaScript and C implementations
  • computes 1 / sinhf( x ), mirroring math/base/special/csch (1 / sinh( x )) and the structure of math/base/special/sechf
  • adds test fixtures generated with Julia (test/fixtures/julia/runner.jl): decimal values in [-80, 80] (an even number of points, so x = 0 is not included), large negative and positive values (|x| in [50, 88]), and tiny negative and positive values (|x| in [1e-38, 1e-30])
  • tests the special cases: NaN, +-0 (returns +-Infinity), +-Infinity (returns +-0), |x| > ~89.416 where sinhf overflows (returns +-0), subnormal inputs whose reciprocal overflows (returns +-Infinity), and that the function is odd

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Reference Packages

Did the content of this pull request follow one or more existing packages? Answering is optional.

This pull request followed these packages:

  • math/base/special/sechf
  • math/base/special/csch
  • math/base/special/cothf

What carried over from the reference(s)?

  • package layout, the JavaScript and C implementations, the native add-on, benchmarks, examples, and the fixture runner from sechf
  • the fixture sets (decimal, large negative and positive, tiny negative and positive) from csch
  • the +-0, odd-function and subnormal tests from cothf

What differed, or what did you have to work out yourself?

  • csch has a pole at zero, so the decimal fixture uses an even number of points to avoid x = 0, whose value (Infinity) cannot be stored in JSON; zero is tested separately
  • the overflow threshold for single precision (sinhf overflows for |x| > ~89.416, so the result is +-0)
  • no equation SVG is included; the README has the equation element only

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.

  • JavaScript tests: all 10,036 assertions pass in test/test.js.
  • C implementation: compiled with -O2 -Wall -Wextra (no warnings) together with its dependencies and checked against the same fixtures with a small harness: at most 2 ULP on the decimal and large sets, exact on the tiny sets, and all special cases above pass. The C example and C benchmark compile and run.
  • I did not build the Node add-on locally, so test/test.native.js was not run here.
  • The fixtures were generated with Julia 1.13 and JSON.jl 1.13; the output format matches the existing sechf fixtures.

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.".

This PR was written primarily by Claude Code, which adapted the package from math/base/special/sechf, generated the fixtures with Julia, and ran the JavaScript tests and a C harness against them. I reviewed the diff before submitting.


@stdlib-js/reviewers

@devxsubh
devxsubh requested a review from a team November 10, 2026 16:12
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Nov 10, 2026
@stdlib-bot

stdlib-bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/cschf $\\color{green}170/170$
$\\color{green}+0.00\\%$
$\\color{green}5/5$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}170/170$
$\\color{green}+0.00\\%$

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

This branch has not been deployed

No deployments
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 Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants