]> sourceware.org Git - newlib-cygwin.git/commitdiff
libm/math: Make yx functions set errno=ERANGE for x=0
authorKeith Packard via Newlib <newlib@sourceware.org>
Tue, 4 Aug 2020 22:22:21 +0000 (15:22 -0700)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 5 Aug 2020 20:16:31 +0000 (22:16 +0200)
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>
newlib/libm/math/w_j0.c
newlib/libm/math/w_j1.c
newlib/libm/math/w_jn.c
newlib/libm/math/wf_j0.c
newlib/libm/math/wf_j1.c
newlib/libm/math/wf_jn.c

index b537ef406f2558adaacb8f10abbcca08712dd4bf..47063ff6f1e2dac7328d62db82a0860e48ef7c2a 100644 (file)
@@ -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
 }
 
index 6f25fea27a14ce98a519fb616e441e0730d050d0..0912b6776566844d68d8cf14f403e9ef03368285 100644 (file)
        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
 }
 
index 28a9abc07437dfb77407a734c3a7bd9ba73f9097..4e770ea5c2fbef1ffeb9cfa61edea138118b69e4 100644 (file)
        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
 }
 
index 4d125db7955ca067a01f554b3571f491beec56d1..ed21a01f57083461e8cba130357d54ce7500e619 100644 (file)
@@ -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
 }
 
        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
 }
 
index e178273c52d06dd3ac19c4bedffd01cd24801e1b..a4609ba28b6e4a538b1743d471acf64ce70ce16f 100644 (file)
        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
 }
 
index 3e4632ead2bcbd653a8f68758cae8adb163c5ab6..b82346d79d07c9d03adc4d8a047dab82c81c6160 100644 (file)
@@ -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
 }
 
        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
 }
 
This page took 0.037313 seconds and 5 git commands to generate.