fix: enforce incomplete gamma argument domains - #1203
Conversation
jvdp1
left a comment
There was a problem hiding this comment.
Thank youj for this fix, @truemagic-coder .
Should the specs be also updated?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1203 +/- ##
==========================================
+ Coverage 68.20% 68.33% +0.12%
==========================================
Files 19 19
Lines 2378 2378
==========================================
+ Hits 1622 1625 +3
+ Misses 756 753 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I missed the documented constraint for negative x. For x < 0, p must be a positive integer. I’m fixing the implementation and tests against the spec now, then I’ll rerun the full test suite and verification. |
|
I found two contract issues while checking this against the spec. Real p must reject negative x. Also, the public wrappers currently return early for x == 0, which lets p <= 0 bypass validation. I’m fixing both and adding explicit rejection tests before pushing the update. |
|
Hi @jvdp1 I missed part of the written spec in the first pass. After going back through it, the spec does not need to be updated. It is already clear that for x < 0, p must be a positive integer. I found a few implementation issues while aligning the code to that contract. Real Those cases now have regression coverage. The focused gamma tests pass, the strict compiler diagnostic passes, and the full suite passes 428/428 twice locally with GNU Fortran 15.2.0. Updated commit: Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR updates stdlib_specialfunctions_gamma to enforce the documented argument domains for incomplete gamma routines, especially around negative x handling and p > 0 validation, and expands the test suite to cover these domain rules and edge cases like log_lower_incomplete_gamma(p, 0).
Changes:
- Enforce
p > 0checks and reject negativexfor real-pincomplete gamma overloads; preserve negative-xbehavior for integer-poverloads. - Fix
log_lower_incomplete_gamma(p, 0)to return-Inf(instead of0). - Add new tests for negative-
xinteger-pbehavior,x=0log-lower behavior, and invalid-argument rejection (via a separate test program).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/specialfunctions/test_specialfunctions_gamma.fypp | Adds new positive/negative-domain and x=0 log-lower tests. |
| test/specialfunctions/test_specialfunctions_gamma_invalid.fypp | New test program that asserts invalid domains are rejected. |
| test/specialfunctions/CMakeLists.txt | Registers the new invalid-argument test in CMake. |
| src/specialfunctions/stdlib_specialfunctions_gamma.fypp | Enforces domain rules, fixes log_lower_incomplete_gamma(p,0), and addresses uninitialized-result warnings. |
| CHANGELOG.md | Notes the incomplete-gamma domain enforcement and diagnostics fix under Unreleased. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Fix incomplete gamma handling to match the documented stdlib specification.
For
x >= 0,pmay be a positive integer or positive real.For
x < 0,pmust be a positive integer. Real-poverloads reject the call.Changes
xsupport for integer-poverloads.xin real-poverloads.p > 0before special-case returns.log_lower_incomplete_gamma(p, 0)to return-Inf.pnegative-xpath.Tests
Added coverage for:
pwith nonnegativexpwith negativexpwith negativexplog_lower_incomplete_gamma(p, 0) == -InfNegative-
xinteger-pregressions use a relative tolerance of128*epsilon(kind).Verification
GNU Fortran 15.2.0 locally:
-Werror=maybe-uninitializedcheck: passedIndependent verification by FalseGreen also passed the branch-specific gamma/specification gates.
Assisted-By: Codex