Skip to content

Commit 401d2e0

Browse files
committed
BUG: special: Fix incorrect handling of nan input in gammainc and gammaincc (#22441)
* BUG: Add nan checks in gammainc and gammaincc scalar kernels * TST: Add tests for nan inputs for gammainc(c) * BUG: fix chdtrc out of domain case * TST: Add nan arg tests for chdtr(c)
1 parent 53692ee commit 401d2e0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/xsf/cephes/chdtr.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ namespace xsf {
162162
namespace cephes {
163163

164164
XSF_HOST_DEVICE inline double chdtrc(double df, double x) {
165-
166-
if (x < 0.0)
167-
return 1.0; /* modified by T. Oliphant */
165+
if (x < 0.0) {
166+
set_error("chdtr", SF_ERROR_DOMAIN, NULL);
167+
return (std::numeric_limits<double>::quiet_NaN());
168+
}
168169
return (igamc(df / 2.0, x / 2.0));
169170
}
170171

include/xsf/cephes/igam.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ namespace cephes {
328328
XSF_HOST_DEVICE inline double igam(double a, double x) {
329329
double absxma_a;
330330

331+
if (std::isnan(a) || std::isnan(x)) {
332+
return std::numeric_limits<double>::quiet_NaN();
333+
}
334+
331335
if (x < 0 || a < 0) {
332336
set_error("gammainc", SF_ERROR_DOMAIN, NULL);
333337
return std::numeric_limits<double>::quiet_NaN();
@@ -367,6 +371,10 @@ namespace cephes {
367371
XSF_HOST_DEVICE double igamc(double a, double x) {
368372
double absxma_a;
369373

374+
if (std::isnan(a) || std::isnan(x)) {
375+
return std::numeric_limits<double>::quiet_NaN();
376+
}
377+
370378
if (x < 0 || a < 0) {
371379
set_error("gammaincc", SF_ERROR_DOMAIN, NULL);
372380
return std::numeric_limits<double>::quiet_NaN();

0 commit comments

Comments
 (0)