From 905aa4c01347b4a5deed8b96305f42eb7054d083 Mon Sep 17 00:00:00 2001 From: Keith Packard via Newlib Date: Tue, 4 Aug 2020 15:22:20 -0700 Subject: [PATCH] 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 --- newlib/libm/math/w_gamma.c | 14 ++++---------- newlib/libm/math/w_lgamma.c | 13 ++++--------- newlib/libm/math/wf_gamma.c | 14 ++++---------- newlib/libm/math/wf_lgamma.c | 14 ++++---------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/newlib/libm/math/w_gamma.c b/newlib/libm/math/w_gamma.c index cfded7b5d..b65d5cc4b 100644 --- a/newlib/libm/math/w_gamma.c +++ b/newlib/libm/math/w_gamma.c @@ -155,16 +155,10 @@ in terms of the base return values, although the <[signgam]> global for y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT))); if(_LIB_VERSION == _IEEE_) return y; if(!finite(y)&&finite(x)) { - if(floor(x)==x&&x<=0.0) { - /* gamma(-integer) or gamma(0) */ - errno = EDOM; - } else { - /* gamma(finite) overflow */ - errno = ERANGE; - } - return HUGE_VAL; - } else - return y; + /* gamma(finite) overflow */ + errno = ERANGE; + } + return y; #endif } diff --git a/newlib/libm/math/w_lgamma.c b/newlib/libm/math/w_lgamma.c index 25d12c9c7..c07804779 100644 --- a/newlib/libm/math/w_lgamma.c +++ b/newlib/libm/math/w_lgamma.c @@ -38,15 +38,10 @@ y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT))); if(_LIB_VERSION == _IEEE_) return y; if(!finite(y)&&finite(x)) { - if(floor(x)==x&&x<=0.0) - /* lgamma(-integer) */ - errno = EDOM; - else - /* lgamma(finite) overflow */ - errno = ERANGE; - return HUGE_VAL; - } else - return y; + /* lgamma(finite) overflow */ + errno = ERANGE; + } + return y; #endif } diff --git a/newlib/libm/math/wf_gamma.c b/newlib/libm/math/wf_gamma.c index 0235ff4db..f0284a282 100644 --- a/newlib/libm/math/wf_gamma.c +++ b/newlib/libm/math/wf_gamma.c @@ -32,16 +32,10 @@ y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT))); if(_LIB_VERSION == _IEEE_) return y; if(!finitef(y)&&finitef(x)) { - if(floorf(x)==x&&x<=0.0f) { - /* gammaf(-integer) or gammaf(0) */ - errno = EDOM; - } else { - /* gammaf(finite) overflow */ - errno = ERANGE; - } - return HUGE_VALF; - } else - return y; + /* gammaf(finite) overflow */ + errno = ERANGE; + } + return y; #endif } diff --git a/newlib/libm/math/wf_lgamma.c b/newlib/libm/math/wf_lgamma.c index c644072e4..b232ecfe4 100644 --- a/newlib/libm/math/wf_lgamma.c +++ b/newlib/libm/math/wf_lgamma.c @@ -32,16 +32,10 @@ y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT))); if(_LIB_VERSION == _IEEE_) return y; if(!finitef(y)&&finitef(x)) { - if(floorf(x)==x&&x<=0.0f) { - /* lgammaf(-integer) */ - errno = EDOM; - } else { - /* lgammaf(finite) overflow */ - errno = ERANGE; - } - return HUGE_VALF; - } else - return y; + /* lgammaf(finite) overflow */ + errno = ERANGE; + } + return y; #endif }