Skip to content

feat: add C implementation for math/base/special/polygamma#13419

Open
Planeshifter wants to merge 1 commit into
developfrom
philipp/polygamma-c
Open

feat: add C implementation for math/base/special/polygamma#13419
Planeshifter wants to merge 1 commit into
developfrom
philipp/polygamma-c

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Jul 11, 2026

Copy link
Copy Markdown
Member

Progresses #649.

Description

What is the purpose of this pull request?

This pull request:

  • adds a C implementation for math/base/special/polygamma
  • adds native bindings, tests, benchmarks, and examples
  • updates the package documentation to document the C API
  • extends scripts/evalpoly.js to also generate the compiled polynomial evaluation functions in src/main.c

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.

Implementation notes:

  • The C API is double stdlib_base_polygamma( const int32_t n, const double x ), following the integer-order convention used elsewhere (e.g., ldexp, falling-factorial) and Boost's polygamma(int, T). Non-integer n validation remains on the JS side, matching existing precedent.
  • The port was validated bit-identical to the JS implementation at 167,037 points (all fixtures plus systematic sweeps across every dispatch regime and 100k+ random pairs) when compiled with -ffp-contract=off, with zero NaN/Infinity/sign mismatches.
  • For n >= 13, the cotangent-polynomial table is built via a heap-allocated ping-pong buffer pair (freed before return), as rows can reach ~10⁶ doubles for reachable inputs; a NULL allocation returns NaN.
  • With default floating-point contraction (FMA) on arm64, some exponent-amplified regimes drift from the JS results; the ULP tolerances in test/test.native.js (per RFC [RFC]: Migrate math/base/special packages from relative tolerance testing to ULP difference testing (tracking issue) #11352) were measured accordingly, with the C and JS minima coinciding at every test site.
  • C lint tasks may report missing_dependencies in environments where the required native tooling is not installed.

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 by Claude Code under my direction and guidance, including the C implementation, tests, benchmarks, and documentation. The port was adversarially reviewed and numerically validated against the existing JS implementation (bit-identical at 167,037 validation points), with all design decisions and validation results reviewed by me.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - task: lint_c_examples
    status: missing_dependencies
  - task: lint_c_benchmarks
    status: missing_dependencies
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added the Math Issue or pull request specific to math functionality. label Jul 11, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/polygamma $\\color{red}1333/1385$
$\\color{green}+96.25\\%$
$\\color{red}130/157$
$\\color{green}+82.80\\%$
$\\color{green}17/17$
$\\color{green}+100.00\\%$
$\\color{red}1333/1385$
$\\color{green}+96.25\\%$

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

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Jul 11, 2026
@Planeshifter Planeshifter marked this pull request as ready for review July 11, 2026 03:05
@Planeshifter Planeshifter requested a review from a team July 11, 2026 03:05
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 11, 2026
@Planeshifter Planeshifter requested a review from kgryte July 11, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. 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