Repository navigation
Conversation
…e/quantile` Uses both `x` and `1-x` as returned by `kernelBetaincinv`, instead of computing `1-x` by subtraction, which returns `Infinity` when `x` rounds to `1` (i.e., when the quantile exceeds about `1e16`). Resolves: stdlib-js#17099 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- 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: passed - 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: missing_dependencies - 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 ---
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
…n range
When `1-x` returned by the incomplete beta inverse falls below the smallest normal number, the ratio `x/(1-x)` is not representable and the clamped kernel result would otherwise yield a large finite value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
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: passed
- 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: missing_dependencies
- 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
---
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #17099.
Description
This pull request:
stats/base/dists/betaprime/quantile(lib/main.js,lib/factory.js, andsrc/main.c) returningInfinityfor large but finite quantiles. The quantile was computed asx / ( 1.0 - x )withx = betaincinv( p, alpha, beta ). When the quantile exceeds about1e16,xrounds to1, so1.0 - xis0. For example,quantile( 0.5, 1.0, 0.001 )returnedInfinityinstead of2^1000 - 1 ≈ 1.0715e301.kernelBetaincinv( alpha, beta, p, 1.0 - p )directly, which returns bothxand1-x, and computesx / (1-x)from those two values.betaincinv(lower tail) is a thin wrapper around the same call, sop = 0(0),p = 1(Infinity), andNaNhandling are unchanged.Infinitywhen the kernel's1-xis below the smallest normal number (2.2e-308). The kernel clamps its search at that value, so without this check the ratio would be a large but meaningless finite number (e.g.,quantile( 0.9, 2.0, 0.001 )returned4.494e307instead ofInfinity).Related Issues
This pull request has the following related issues:
Questions
No.
Other
New tests (JS, factory, and native) use 7 cases with
alpha = 1, where the quantile has the closed form(1-p)^(-1/beta) - 1. Reference values were computed with 50 digits of precision, choosingpsuch that1-pis exact in double precision. Errors in ULP:pbetaInfinityInfinityInfinityInfinityInfinityInfinityThe tolerance is 1000 ULP. For small
beta, the inverse is ill-conditioned: a relative errordin the incomplete beta function corresponds to a relative error of aboutd/betain the quantile. Six of the seven checks fail on the previous code.I also checked:
large_alpha), which is within the fixtures' own error. A variant that uses the kernel's1-xonly forx > 0.99keeps the fixture results identical, but is less accurate nearx = 1(max 27 vs. 7 ULP on 179alpha = 1cases withpfrom0.9to1 - 1e-15), so I kept the simpler version.(0.55, 2, 0.001),(0.9, 2, 0.001),(0.6, 0.5, 0.001)) returnInfinity.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
@stdlib-js/reviewers