Skip to content

[BUG]: stats/base/dists/pareto-type1/quantile loses accuracy for small p #17008

Description

@ItsAbir005

Description

In @stdlib/stats/base/dists/pareto-type1/quantile, the quantile function is currently computed as:

beta / pow( 1.0 - p, 1.0 / alpha );

(and beta / pow( 1.0 - p, alphaInv ) in lib/factory.js, and beta / stdlib_base_pow( 1.0 - p, 1.0/alpha ) in src/main.c).

For small probabilities p, evaluating 1.0 - p suffers from floating-point cancellation and rounds to 1.0 when p < 1.11e-16. As a result, pow( 1.0 - p, ... ) evaluates to 1.0, causing the function to return beta instead of the true quantile. When alpha is also small, this produces large relative errors.

Replacing beta / pow( 1.0 - p, 1.0 / alpha ) with beta * exp( -log1p( -p ) / alpha ) (and handling p === 1.0 explicitly by returning +Infinity) avoids cancellation in 1.0 - p.

Related Issues

None. (Related to similar log1p/expm1 tail accuracy fixes such as #15762, #15763, #15769, and #16565.)

Questions

None.

Demo

No response

Reproduction

var quantile = require( '@stdlib/stats/base/dists/pareto-type1/quantile' );

quantile( 3.487713003317677e-14, 3.770177179633989e-15, 3.1006509521973644 );
quantile( 9.848016845161383e-17, 4.028717220737787e-17, 0.6831483634551567 );
quantile( 1.3302736633414168e-17, 2.201607940364203e-18, 0.6003661040099838 );
quantile( 3.627963640422887e-15, 6.742762523455147e-16, 1.30847092784763 );
quantile( 1.590320234441396e-19, 2.1816061229888833e-20, 1.4297727967473501 );

Expected Results

Computed with 100-digit mpmath:
- 32286.5313986437347
- 7.87278208484850842
- 252.665540030620453
- 284.11789600200217
- 2094.75483060059775

Actual Results

- 32148.719629853116 (rel err: 4.268e-03)
- 10.748108721407508 (rel err: 3.652e-01)
- 0.6003661040099838 (returns beta; rel err: 9.976e-01)
- 299.5981940197779 (rel err: 5.449e-02)
- 1.4297727967473501 (returns beta; rel err: 9.993e-01)

Version

develop (008bd34)

Environments

Node.js

Browser Version

No response

Node.js / npm Version

Node.js v24.19.0

Platform

Windows / Linux (Codespaces)

Checklist

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

Activity

  1. added 3 commits that reference this issue on Nov 30, 2026
    63040aa
    a20bb77
    32d7d61
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