Skip to content

[BUG]: math/base/special/gammainc is off by up to 0.03 for x > 1000 when a is close to x #16533

Open

Description

@trackoor

Description

Encountered an error when evaluating gammainc with x > 1000 and a near x. The large-x asymptotic series (tgamma_i_large_x_series.js) starts its falling factorial at a instead of a - 1, so results are off by up to a few percent. This propagates to stats/base/dists/poisson/cdf, chisquare/cdf, gamma/cdf and others for large parameters.

In lib/node_modules/@stdlib/math/base/special/gammainc/lib/tgamma_i_large_x_series.js, var a = a1; should be var a = a1 - 1.0;, matching Boost's incomplete_tgamma_large_x_series (a_poch(a - 1)). With that one-line change the four values below match SciPy. The C implementation in src/main.c (ac = a; at line 703, in the same series) has the same off-by-one.

Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.

Related Issues

None.

Questions

No.

Demo

https://trackoor.github.io/stdlib-gammainc-large-x-repro/ (source: https://github.com/trackoor/stdlib-gammainc-large-x-repro). It shows the first three values from the jsDelivr ESM build; the chisqCDF value is only wrong in the npm build.

Reproduction

  • npm i @stdlib/math-base-special-gammainc@0.3.1 @stdlib/stats-base-dists-poisson-cdf@0.3.1 @stdlib/stats-base-dists-chisquare-cdf@0.3.1
  • save as t.js and run node t.js:
var gammainc = require( '@stdlib/math-base-special-gammainc' );
var poissonCDF = require( '@stdlib/stats-base-dists-poisson-cdf' );
var chisqCDF = require( '@stdlib/stats-base-dists-chisquare-cdf' );

console.log( gammainc( 1367.3436948118986, 1409.203708740708 ) );
console.log( gammainc( 1001, 1000.5, true, true ) );
console.log( poissonCDF( 999, 1001 ) );
console.log( chisqCDF( 2500, 2400 ) );

Expected Results

0.13190499189857086
0.489491914600245
0.48318854707021375
0.9241270884571916

(SciPy 1.10.1: gammainc(1409.203708740708, 1367.3436948118986), gammaincc(1000.5, 1001), poisson.cdf(999, 1001), chi2.cdf(2500, 2400))

Actual Results

0.09952119051642438
0.501850998882592
0.49530155533410974
0.9231500432608719

Version

@stdlib/math-base-special-gammainc 0.3.1; same code on develop 734972c

Environments

Node.js

Browser Version

Chrome 152 for the demo page; the report itself uses Node.js.

Node.js / npm Version

v26.13.0

Platform

Linux

Checklist

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

Credit: https://ucsbplse.github.io/

Activity

  1. stdlib-bot commented on Nov 7, 2026

    @stdlib-bot
    Contributor

    👋 Hi there! 👋

    And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

    If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members.

  2. added
    BugSomething isn't working.
    MathIssue or pull request specific to math functionality.
    Numerical AccuracyIssue or pull request concerns numerical accuracy.
    on Nov 8, 2026
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

    BugSomething isn't working.MathIssue or pull request specific to math functionality.Numerical AccuracyIssue or pull request concerns numerical accuracy.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions