Skip to content

feat: add C implementation for math/base/special/kernel-betaincinv#13418

Open
Planeshifter wants to merge 2 commits into
developfrom
philipp/kernel-betaincinv-c
Open

feat: add C implementation for math/base/special/kernel-betaincinv#13418
Planeshifter wants to merge 2 commits into
developfrom
philipp/kernel-betaincinv-c

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Jul 11, 2026

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • adds a C implementation for @stdlib/math/base/special/kernel-betaincinv
  • adds a native add-on binding, C benchmarks, C examples, native tests, and documentation for the C API
  • extends scripts/evalpoly.js to generate the C polynomial evaluation functions (spliced into src/main.c between auto-generated markers), keeping the JS and C polynomial coefficients in sync from a single source

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 implementation is a faithful port of the existing JavaScript implementation (Boost ibeta_inverse.hpp, t_distribution_inv.hpp, and roots.hpp), preserving branch structure, constants, and iteration behavior.
  • As @stdlib/math/base/special/betainc does not yet have a C implementation, the two call sites in the driver use stdlib_base_kernel_betainc( x, a, b, true, false, &out, &deriv ) directly, mirroring what the JS betainc wrapper does.
  • The JS implementation computes ldexp( 1.0, (2.0*53.0)/3.0 ); the JS ldexp truncates the fractional exponent, so the C port uses stdlib_base_ldexp( 1.0, 35 ) to match runtime behavior.
  • The C API follows the multi-output pointer pattern of @stdlib/math/base/special/kernel-betainc: void stdlib_base_kernel_betaincinv( const double a, const double b, const double p, const double q, double *out1, double *out2 ).
  • Native tests pass the full C++ (Boost) fixture set (2000 cases) within 16 ULP (empirical minimum, deterministic). Differential testing against the JS implementation over >150k random and edge-case inputs shows agreement, with residual-level analysis confirming remaining ULP spread is root-finder termination conditioning rather than porting divergence.

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 under my direction, using a multi-agent workflow: the JS implementation and existing C ports (gammaincinv, kernel-betainc) were studied in detail, the port was generated to mirror the JS line-by-line, and the result was verified via fixture tests, large-scale differential testing against the JS implementation, and multiple independent adversarial review passes. All design decisions and validation results were 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: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - 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
---
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: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - 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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/kernel-betaincinv $\\color{red}2616/3235$
$\\color{green}+80.87\\%$
$\\color{red}116/170$
$\\color{green}+68.24\\%$
$\\color{red}24/38$
$\\color{green}+63.16\\%$
$\\color{red}2616/3235$
$\\color{green}+80.87\\%$

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

@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

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