Skip to content

fix: return 0 when p = 1 in stats/base/dists/negative-binomial/quantile - #15956

Draft
Planeshifter wants to merge 1 commit into
developfrom
claude/great-cerf-8v9eo2
Draft

Planeshifter wants to merge 1 commit into
developfrom
claude/great-cerf-8v9eo2

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

Follow-up fixes for commits merged to develop between 2026-10-06T15:35:50Z and 2026-10-06T15:43:19Z (25b78b3fe..5fc7eb73c).

This pull request:

  • stats/base/dists/negative-binomial/quantile
    • quantile( 0.5, 10, 1.0 ) returns NaN in both JS and the new C implementation (5fc7eb7, lib/main.js, lib/factory.js, src/main.c). At p = 1 the distribution is degenerate at 0, but sigmaInv is Infinity, so the Cornish-Fisher guess is NaN. Before 5fc7eb7 this input hung in searchRight; the new loop guards now return the NaN. This PR short-circuits p = 1 to 0 after argument validation, mirroring binomial/quantile, and adds tests to test.main.js, test.factory.js and test.native.js.
    • 5fc7eb7 dropped the blank line before // Cornish-Fisher expansion: in lib/factory.js, and the new // If the mean overflows ... comment also has no blank line before it. Both blank lines are restored, per stdlib/empty-line-before-comment.

Related Issues

Does this pull request have any related issues?

No.

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.

Validation

  • Commits reviewed: 25b78b3 (betaprime/cdf C impl), 27712bc (negative-binomial/pmf C impl), 5fc7eb7 (negative-binomial/quantile C impl).
  • Checks: style guide compliance against reference packages (beta/cdf, binomial/pmf, binomial/quantile), plus two independent bug scans. Doc and example values were confirmed against actual output.
  • The JS tests for negative-binomial/quantile pass locally. I ran them with a minimal tape stand-in.
  • Deliberately excluded (out of scope or needs judgment):
    • negative-binomial/pmf at p = 1: the C implementation returns 1/r at x = 0 and the JS returns 0. Both are wrong, since the expected value is 1. The divergence comes from math/base/special/kernel-betainc vs. the JS ibeta_derivative, which are outside this diff. Worth a separate follow-up.
    • negative-binomial/quantile with very small p (e.g., quantile( 0.5, 10, 1e-10 )) is slow because the search uses unit steps. This predates the window.

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 as part of an automated daily review of commits merged to develop.


🤖 Generated with Claude Code

https://claude.ai/code/session_01Cio3EetT4BiFSZQWkoKDeW


Generated by Claude Code

…uantile`

When `p = 1`, the distribution is degenerate at `0`, but the Cornish-Fisher initial guess evaluates to `NaN` (`sigmaInv = Infinity`), causing the JS and C implementations to return `NaN`. Additionally restores the blank lines before line comments in `lib/factory.js` (`stdlib/empty-line-before-comment`).

Ref: 5fc7eb7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cio3EetT4BiFSZQWkoKDeW
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Oct 7, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/negative-binomial/quantile $\\color{green}536/536$
$\\color{green}+100.00\\%$
$\\color{green}66/66$
$\\color{green}+100.00\\%$
$\\color{green}6/6$
$\\color{green}+100.00\\%$
$\\color{green}536/536$
$\\color{green}+100.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

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants