diff options
author | Keith Packard via Newlib <newlib@sourceware.org> | 2020-08-04 15:22:21 -0700 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2020-08-05 22:16:31 +0200 |
commit | 2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe (patch) | |
tree | b05f3721b04fbae77a47e8582c009d6bf622e82e | |
parent | 905aa4c01347b4a5deed8b96305f42eb7054d083 (diff) | |
download | newlib-2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe.zip newlib-2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe.tar.gz newlib-2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe.tar.bz2 |
libm/math: Make yx functions set errno=ERANGE for x=0
The y0, y1 and yn functions need separate conditions when x is zero as
that returns ERANGE instead of EDOM.
Also stop adjusting the return value from the __ieee754_y* functions
as that is already correct and we were just breaking it.
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | newlib/libm/math/w_j0.c | 14 | ||||
-rw-r--r-- | newlib/libm/math/w_j1.c | 14 | ||||
-rw-r--r-- | newlib/libm/math/w_jn.c | 14 | ||||
-rw-r--r-- | newlib/libm/math/wf_j0.c | 19 | ||||
-rw-r--r-- | newlib/libm/math/wf_j1.c | 14 | ||||
-rw-r--r-- | newlib/libm/math/wf_jn.c | 19 |
6 files changed, 52 insertions, 42 deletions
diff --git a/newlib/libm/math/w_j0.c b/newlib/libm/math/w_j0.c index b537ef4..47063ff 100644 --- a/newlib/libm/math/w_j0.c +++ b/newlib/libm/math/w_j0.c @@ -128,17 +128,19 @@ None of the Bessel functions are in ANSI C. double z; z = __ieee754_y0(x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= 0.0){ - /* y0(0) = -inf or y0(x<0) = NaN */ + if(x < 0.0){ + /* y0(x<0) = NaN */ errno = EDOM; - return -HUGE_VAL; + } + if(x == 0.0){ + /* y0(0) = -inf */ + errno = ERANGE; } if(x>X_TLOSS) { /* y0(x>X_TLOSS) */ errno = ERANGE; - return 0.0; - } else - return z; + } + return z; #endif } diff --git a/newlib/libm/math/w_j1.c b/newlib/libm/math/w_j1.c index 6f25fea..0912b67 100644 --- a/newlib/libm/math/w_j1.c +++ b/newlib/libm/math/w_j1.c @@ -55,17 +55,19 @@ double z; z = __ieee754_y1(x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= 0.0){ - /* y1(0) = -inf or y1(x<0) = NaN */ + if(x < 0.0){ + /* y1(x<0) = NaN */ errno = EDOM; - return -HUGE_VAL; + } + if(x == 0.0){ + /* y1(0) = -inf */ + errno = ERANGE; } if(x>X_TLOSS) { /* y1(x>X_TLOSS) */ errno = ERANGE; - return 0.0; - } else - return z; + } + return z; #endif } diff --git a/newlib/libm/math/w_jn.c b/newlib/libm/math/w_jn.c index 28a9abc..4e770ea 100644 --- a/newlib/libm/math/w_jn.c +++ b/newlib/libm/math/w_jn.c @@ -77,17 +77,19 @@ double z; z = __ieee754_yn(n,x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= 0.0){ - /* yn(n,0) = -inf or yn(x<0) = NaN */ + if(x < 0.0){ + /* yn(x<0) = NaN */ errno = EDOM; - return -HUGE_VAL; + } + if(x == 0.0){ + /* yn(0) = -inf */ + errno = ERANGE; } if(x>X_TLOSS) { /* yn(x>X_TLOSS) */ errno = ERANGE; - return 0.0; - } else - return z; + } + return z; #endif } diff --git a/newlib/libm/math/wf_j0.c b/newlib/libm/math/wf_j0.c index 4d125db..ed21a01 100644 --- a/newlib/libm/math/wf_j0.c +++ b/newlib/libm/math/wf_j0.c @@ -35,9 +35,8 @@ if(fabsf(x)>(float)X_TLOSS) { /* j0f(|x|>X_TLOSS) */ errno = ERANGE; - return 0.0f; - } else - return z; + } + return z; #endif } @@ -54,17 +53,19 @@ float z; z = __ieee754_y0f(x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= (float)0.0){ - /* y0f(0) = -inf or y0f(x<0) = NaN */ + if(x < 0.0f){ + /* y0f(x<0) = NaN */ errno = EDOM; - return -HUGE_VALF; } + if (x == 0.0f){ + /* y0f(n,0) = -inf */ + errno = ERANGE; + } if(x>(float)X_TLOSS) { /* y0f(x>X_TLOSS) */ errno = ERANGE; - return 0.0f; - } else - return z; + } + return z; #endif } diff --git a/newlib/libm/math/wf_j1.c b/newlib/libm/math/wf_j1.c index e178273..a4609ba 100644 --- a/newlib/libm/math/wf_j1.c +++ b/newlib/libm/math/wf_j1.c @@ -56,17 +56,19 @@ float z; z = __ieee754_y1f(x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= 0.0f){ - /* y1f(0) = -inf or y1f(x<0) = NaN */ + if(x < 0.0f){ + /* y1f(x<0) = NaN */ errno = EDOM; - return -HUGE_VALF; } + if (x == 0.0f){ + /* y1f(n,0) = -inf */ + errno = ERANGE; + } if(x>(float)X_TLOSS) { /* y1f(x>X_TLOSS) */ errno = ERANGE; - return 0.0f; - } else - return z; + } + return z; #endif } diff --git a/newlib/libm/math/wf_jn.c b/newlib/libm/math/wf_jn.c index 3e4632e..b82346d 100644 --- a/newlib/libm/math/wf_jn.c +++ b/newlib/libm/math/wf_jn.c @@ -33,9 +33,8 @@ if(fabsf(x)>(float)X_TLOSS) { /* jnf(|x|>X_TLOSS) */ errno = ERANGE; - return 0.0f; - } else - return z; + } + return z; #endif } @@ -52,17 +51,19 @@ float z; z = __ieee754_ynf(n,x); if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; - if(x <= 0.0f){ - /* ynf(n,0) = -inf or ynf(x<0) = NaN */ + if(x < 0.0f){ + /* ynf(x<0) = NaN */ errno = EDOM; - return -HUGE_VALF; } + if (x == 0.0f){ + /* ynf(n,0) = -inf */ + errno = ERANGE; + } if(x>(float)X_TLOSS) { /* ynf(x>X_TLOSS) */ errno = ERANGE; - return 0.0f; - } else - return z; + } + return z; #endif } |