Skip to content

fix: resolve Infinity results for large finite quantiles in stats/base/dists/betaprime/quantile - #17136

Open
wanjinhao1 wants to merge 2 commits into
stdlib-js:developfrom
wanjinhao1:agent/fix-17099-betaprime-quantile
Open

wanjinhao1 wants to merge 2 commits into
stdlib-js:developfrom
wanjinhao1:agent/fix-17099-betaprime-quantile

Conversation

@wanjinhao1

Copy link
Copy Markdown
Contributor

Resolves #17099.

Description

What is the purpose of this pull request?

This pull request:

  • Fixes stats/base/dists/betaprime/quantile returning Infinity for large finite quantiles. Previously the quantile was computed as x / (1.0 - x) where x = betaincinv(p, alpha, beta); when the true quantile exceeds ~1e16, x rounds to 1.0 and 1.0 - x is 0. Now both lib/main.js, lib/factory.js, and src/main.c call kernelBetaincinv(alpha, beta, p, 1.0-p), which returns both x and 1-x without a catastrophic cancellation, and compute x / (1-x) from the two returned values (the approach suggested in the issue). manifest.json swaps the betaincinv add-on dependency for kernel-betaincinv, matching how stats/base/dists/f/quantile is wired.

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:

  • stats/base/dists/f/quantile

What carried over from the reference(s)?

  • The kernel-betaincinv usage pattern (JS and C, including the manifest add-on dependency declarations).

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

  • The regression test cases and expected values from the issue report.

Questions

Any questions for reviewers of this pull request?

No.

Other

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

The issue's three reproduction cases now return 9.999999999999112e+199, 1.071508607186194e+301, and 1.0000000000000554e+250, within a few ULP of the closed-form reference values. Small/ordinary quantiles are unchanged.

Checklist

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

  • Read, understood, and followed the [contributing guidelines][contributing].

AI Assistance

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

  • Yes

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

AI assistance (Claude Code agent operated by the repository contributor wanjinhao1) was used to analyze the issue, implement the fix, add the regression tests, and draft this pull request. The fix approach was proposed in the issue itself; the contributor reviewed and verified the changes locally: node test/test.js, node test/test.quantile.js (3024 tests, including 3 new regression cases), node test/test.factory.js (3023 tests) all pass, and the C side passes gcc -fsyntax-only.

@wanjinhao1
wanjinhao1 requested a review from a team December 3, 2026 20:07
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Dec 3, 2026
@stdlib-bot

stdlib-bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/betaprime/quantile $\\color{green}314/314$
$\\color{green}+0.00\\%$
$\\color{green}25/25$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}314/314$
$\\color{green}+0.00\\%$

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

@wanjinhao1 wanjinhao1 changed the title Fix #17099: betaprime quantile returns Infinity for large finite quantiles fix: resolve Infinity results for large finite quantiles in stats/base/dists/betaprime/quantile Dec 3, 2026

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

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: stats/base/dists/betaprime/quantile returns Infinity for large finite quantiles

2 participants