Skip to content

fix: avoid overflow in stats/base/dists/rayleigh/quantile - #14480

Merged
kgryte merged 1 commit into
developfrom
claude/ecstatic-heisenberg-fgld3o
Aug 22, 2026
Merged

kgryte merged 1 commit into
developfrom
claude/ecstatic-heisenberg-fgld3o

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • propagates fixes merged to develop between 2026-08-20 and 2026-08-21 to sibling packages.

Propagates the overflow fix from f51d7fe (#14446) to @stdlib/stats/base/dists/rayleigh/quantile. Computing sigma*sigma overflows for sigma > ~1.34e154, returning Infinity for every p, and underflows to 0 for sigma < ~1.5e-154; replacing sqrt( -2.0 * s2 * log1p( -p ) ) with sigma * sqrt( -2.0 * log1p( -p ) ) avoids the intermediate square and returns correct finite values across the full sigma range. Applied identically to the JS main.js, factory.js, and C main.c implementations; all 3000 Julia fixture values pass at the existing 1.0 * EPS tolerance.

  • lib/node_modules/@stdlib/stats/base/dists/rayleigh/quantile/lib/main.js
  • lib/node_modules/@stdlib/stats/base/dists/rayleigh/quantile/lib/factory.js
  • lib/node_modules/@stdlib/stats/base/dists/rayleigh/quantile/src/main.c

Related Issues

Does this pull request have any related issues?

No 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.

Validation performed: signature search over stats/base/dists/* for pow( sigma, 2.0 ) / sigma * sigma kernels; two independent validation passes confirming the defect and guard preservation at each site (edge cases sigma === 0, sigma === Infinity, p === 0, p === 1, NaN verified bit-identical); an adaptation pass producing per-file patches; and a style-consistency pass against the conventions of f51d7fe. Existing Julia fixtures were re-run against the patched code: 0/3000 failures for both quantile and factory paths.

Deliberately excluded: rayleigh/{pdf,logpdf,cdf,logcdf} carry the same sigma^2 overflow defect, but their test fixtures were generated by Julia code using the same squared-form algebra at 0–2 ULP tolerances, so the ratio-form fix shifts results by up to ~1180 ULP through exp() amplification and fails 1–1146 of 3000 fixture assertions per package. Landing those requires loosening tolerances (as already done for normal/*, lognormal/*, and halfnormal/logpdf) or regenerating fixtures — a reviewer decision, so they are left out of this propagation. wald/logpdf was checked and is already fixed (#14412).

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 authored by Claude Code as part of an automated fix-propagation routine: candidate sites were located by pattern search, validated by independent review passes, and verified against the existing Julia test fixtures before committing.


@stdlib-js/reviewers


Generated by Claude Code

Propagates fix from f51d7fe ("fix: avoid overflow and duplicate
computation") to the Rayleigh quantile function, which computed an
unnecessary intermediate `sigma*sigma` that overflows to infinity for
`sigma > ~1.34e154` (returning `Infinity` for all probabilities) and
underflows for `sigma < ~1.5e-154` (returning `0`). Factoring `sigma`
out of the square root avoids the squaring entirely.

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/rayleigh/quantile $\\color{green}286/286$
$\\color{green}+100.00\\%$
$\\color{green}26/26$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}286/286$
$\\color{green}+100.00\\%$

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

@kgryte
kgryte marked this pull request as ready for review August 22, 2026 00:15
@kgryte
kgryte requested a review from a team August 22, 2026 00:15
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 22, 2026
@kgryte
kgryte merged commit a344e9b into develop Aug 22, 2026
50 checks passed
@kgryte
kgryte deleted the claude/ecstatic-heisenberg-fgld3o branch August 22, 2026 00:16
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 22, 2026
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.

4 participants