Patchwork [BZ,#22244] Fix yn(n,0) without SVID wrapper

login
register
mail settings
Submitter Szabolcs Nagy
Date Oct. 3, 2017, 5:28 p.m.
Message ID <59D3C8B2.9020204@arm.com>
Download mbox | patch
Permalink /patch/23303/
State New
Headers show

Comments

Szabolcs Nagy - Oct. 3, 2017, 5:28 p.m.
Without SVID compat wrapper yn(n,0) and ynf(n,0) does not raise
the divide-by-zero excpetion and it may return inf with the wrong
sign for n < 0.

2017-10-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	[BZ #22244]
	* sysdeps/ieee754/dbl-64/e_jn.c (__ieee754_yn): Fix x == 0 case.
	* sysdeps/ieee754/flt-32/e_jnf.c (__ieee754_ynf): Likewise.
Szabolcs Nagy - Oct. 3, 2017, 5:34 p.m.
On 03/10/17 18:28, Szabolcs Nagy wrote:
> Without SVID compat wrapper yn(n,0) and ynf(n,0) does not raise
> the divide-by-zero excpetion and it may return inf with the wrong
> sign for n < 0.
> 
> 2017-10-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>
> 
> 	[BZ #22244]
> 	* sysdeps/ieee754/dbl-64/e_jn.c (__ieee754_yn): Fix x == 0 case.
> 	* sysdeps/ieee754/flt-32/e_jnf.c (__ieee754_ynf): Likewise.
> 

sorry, wrong patch (this one breaks yn(n,-0))

Patch

diff --git a/sysdeps/ieee754/dbl-64/e_jn.c b/sysdeps/ieee754/dbl-64/e_jn.c
index 3ac91df2b0..4efeec402b 100644
--- a/sysdeps/ieee754/dbl-64/e_jn.c
+++ b/sysdeps/ieee754/dbl-64/e_jn.c
@@ -268,8 +268,6 @@  __ieee754_yn (int n, double x)
   /* if Y(n,NaN) is NaN */
   if (__glibc_unlikely ((ix | ((uint32_t) (lx | -lx)) >> 31) > 0x7ff00000))
     return x + x;
-  if (__glibc_unlikely ((ix | lx) == 0))
-    return -HUGE_VAL + x;
   /* -inf and overflow exception.  */;
   if (__glibc_unlikely (hx < 0))
     return zero / (zero * x);
@@ -281,6 +279,8 @@  __ieee754_yn (int n, double x)
     }
   if (n == 0)
     return (__ieee754_y0 (x));
+  if (__glibc_unlikely ((ix | lx) == 0))
+    return -sign / zero;
   {
     SET_RESTORE_ROUND (FE_TONEAREST);
     if (n == 1)
diff --git a/sysdeps/ieee754/flt-32/e_jnf.c b/sysdeps/ieee754/flt-32/e_jnf.c
index 82b9ba3300..da014ac1ed 100644
--- a/sysdeps/ieee754/flt-32/e_jnf.c
+++ b/sysdeps/ieee754/flt-32/e_jnf.c
@@ -194,8 +194,6 @@  __ieee754_ynf(int n, float x)
 	ix = 0x7fffffff&hx;
     /* if Y(n,NaN) is NaN */
 	if(__builtin_expect(ix>0x7f800000, 0)) return x+x;
-	if(__builtin_expect(ix==0, 0))
-		return -HUGE_VALF+x;  /* -inf and overflow exception.  */
 	if(__builtin_expect(hx<0, 0)) return zero/(zero*x);
 	sign = 1;
 	if(n<0){
@@ -203,6 +201,8 @@  __ieee754_ynf(int n, float x)
 		sign = 1 - ((n&1)<<1);
 	}
 	if(n==0) return(__ieee754_y0f(x));
+	if(__builtin_expect(ix==0, 0))
+		return -sign/zero;
 	SET_RESTORE_ROUNDF (FE_TONEAREST);
 	if(n==1) {
 	    ret = sign*__ieee754_y1f(x);