Skip to content

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

Backlog

Description

@Udaygund

Description

stats/base/dists/betaprime/quantile returns Infinity when the quantile is large but finite. For example, quantile( 0.5, 1.0, 0.001 ) returns Infinity. With alpha = 1, the CDF is 1 - (1+x)^(-beta), so the quantile is (1-p)^(-1/beta) - 1, which is 2^1000 - 1 ≈ 1.0715e301 here.

The quantile is computed as x / ( 1.0 - x ), where x = betaincinv( p, alpha, beta ) (lib/main.js and src/main.c). When the quantile is above about 1e16, x rounds to 1.0, so 1.0 - x is 0 and the result is Infinity.

A possible fix: call kernelBetaincinv( alpha, beta, p, 1.0-p ), which returns both x and 1-x, and compute x / (1-x) from those two values instead of computing 1-x by subtraction. I tested this on the cases below. It gives finite results within 0 to 616 ULP of the exact values (the current implementation is off by about 1e17 to 2e18 ULP, i.e. returns Infinity).

Found while comparing stats/base/dists functions against SciPy and mpmath. The comparison and this report were done with AI assistance (Claude Code); I checked the reproduction and reference values.

Related Issues

None.

Questions

No.

Demo

No response

Reproduction

var quantile = require( '@stdlib/stats/base/dists/betaprime/quantile' );

console.log( quantile( 0.99, 1.0, 0.01 ) );
console.log( quantile( 0.5, 1.0, 0.001 ) );
console.log( quantile( 0.9, 1.0, 0.004 ) );

Expected Results

9.999999999999112e+199
1.0715086071862673e+301
1.0000000000000556e+250

Reference values from the closed form for alpha = 1, (1-p)^(-1/beta) - 1. For these p, 1-p is exact in double precision.

Actual Results

Infinity
Infinity
Infinity

Version

develop (2c54daf)

Environments

Node.js

Browser Version

N/A

Node.js / npm Version

Node.js v22.16.0

Platform

macOS

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions