Skip to content

Avoid overflow in gamma_inc derivatives - #862

Open
vera-rubin wants to merge 1 commit into
JuliaDiff:masterfrom
vera-rubin:fix/gamma-inc-derivative-overflow
Open

vera-rubin wants to merge 1 commit into
JuliaDiff:masterfrom
vera-rubin:fix/gamma-inc-derivative-overflow

Conversation

@vera-rubin

Copy link
Copy Markdown

Differentiating gamma_inc(a, x, 0) with respect to x at a = x = 150.0 or 200.0 returns Inf or NaN:

using ForwardDiff, SpecialFunctions
for a in (150.0, 200.0)
    @show ForwardDiff.derivative(x -> gamma_inc(a, x, 0)[1], a)
end

The documented normalization and derivative identity give finite derivatives of about 0.03255540946 and 0.02819772769, respectively.

We evaluate the derivative in log space using loggamma to avoid overflowing intermediate values while retaining the power rule at zero for higher derivatives.

The new regression tests and the existing dual-number tests pass.

Tested versions: ForwardDiff 1.4.6, Julia 1.10.12, SpecialFunctions 2.9.0.

— ChipLab

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (a3c0f4f) to head (a90c217).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #862      +/-   ##
==========================================
+ Coverage   91.23%   91.25%   +0.02%     
==========================================
  Files          11       11              
  Lines        1072     1075       +3     
==========================================
+ Hits          978      981       +3     
  Misses         94       94              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant