libm/math: set errno to ERANGE at gamma poles

For POSIX, gamma(i) (i non-positive integer) should set errno to
ERANGE instead of EDOM.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard via Newlib 2020-08-04 15:22:20 -07:00 committed by Corinna Vinschen
parent 50ad198085
commit 905aa4c013
4 changed files with 16 additions and 39 deletions

View File

@ -155,15 +155,9 @@ in terms of the base return values, although the <[signgam]> global for
y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT))); y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y; if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) { if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0) {
/* gamma(-integer) or gamma(0) */
errno = EDOM;
} else {
/* gamma(finite) overflow */ /* gamma(finite) overflow */
errno = ERANGE; errno = ERANGE;
} }
return HUGE_VAL;
} else
return y; return y;
#endif #endif
} }

View File

@ -38,14 +38,9 @@
y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT))); y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y; if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) { if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
/* lgamma(-integer) */
errno = EDOM;
else
/* lgamma(finite) overflow */ /* lgamma(finite) overflow */
errno = ERANGE; errno = ERANGE;
return HUGE_VAL; }
} else
return y; return y;
#endif #endif
} }

View File

@ -32,15 +32,9 @@
y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT))); y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y; if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) { if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=0.0f) {
/* gammaf(-integer) or gammaf(0) */
errno = EDOM;
} else {
/* gammaf(finite) overflow */ /* gammaf(finite) overflow */
errno = ERANGE; errno = ERANGE;
} }
return HUGE_VALF;
} else
return y; return y;
#endif #endif
} }

View File

@ -32,15 +32,9 @@
y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT))); y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y; if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) { if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=0.0f) {
/* lgammaf(-integer) */
errno = EDOM;
} else {
/* lgammaf(finite) overflow */ /* lgammaf(finite) overflow */
errno = ERANGE; errno = ERANGE;
} }
return HUGE_VALF;
} else
return y; return y;
#endif #endif
} }