This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix nexttoward bugs (bugs 2550, 2570)


On 05/01/2012 07:03 AM, Joseph S. Myers wrote:
> [...] I didn't change the ldbl-128ibm
> implementation of nexttoward (double); I don't expect that format to
> suffer from subnormal-related bugs, given that the exponent range for
> double and long double is the same.
>
Looks like your additional tests hit some narrow cases, I saw the following issues on
a PPC32 build:

Failure: Test: nexttoward (1.0, 1.1) == 0x1.0000000000001p0
Result:
 is:          9.99999999999999888978e-01   0x1.fffffffffffff0000000p-1
 should be:   1.00000000000000022204e+00   0x1.00000000000010000000p+0
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  1.5000
 max.ulp   :  0.0000
Failure: Test: nexttoward (1.0, 0x1.0000000000001p0) == 0x1.0000000000001p0
Result:
 is:          9.99999999999999888978e-01   0x1.fffffffffffff0000000p-1
 should be:   1.00000000000000022204e+00   0x1.00000000000010000000p+0
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  1.5000
 max.ulp   :  0.0000
Failure: Test: nexttoward (1.0, 0x1.000000000000002p0) == 0x1.0000000000001p0
Result:
 is:          9.99999999999999888978e-01   0x1.fffffffffffff0000000p-1
 should be:   1.00000000000000022204e+00   0x1.00000000000010000000p+0
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  1.5000
 max.ulp   :  0.0000
Failure: Test: nexttoward (-1.0, -0x0.ffffffffffffffffp0) == -0x0.fffffffffffff8p0
Result:
 is:         -1.00000000000000022204e+00  -0x1.00000000000010000000p+0
 should be:  -9.99999999999999888978e-01  -0x1.fffffffffffff0000000p-1
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  3.0000
 max.ulp   :  0.0000
Failure: Test: nexttoward (1.0, 0x1.000000000000000000000000008p0) == 0x1.0000000000001p0
Result:
 is:          9.99999999999999888978e-01   0x1.fffffffffffff0000000p-1
 should be:   1.00000000000000022204e+00   0x1.00000000000010000000p+0
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  1.5000
 max.ulp   :  0.0000
Failure: Test: nexttoward (-1.0, -0x0.ffffffffffffffffffffffffffcp0) == -0x0.fffffffffffff8p0
Result:
 is:         -1.00000000000000022204e+00  -0x1.00000000000010000000p+0
 should be:  -9.99999999999999888978e-01  -0x1.fffffffffffff0000000p-1
 difference:  3.33066907387546962127e-16   0x1.80000000000000000000p-52
 ulp       :  3.0000
 max.ulp   :  0.0000

Below there is a patch based on your previous one that fixes it:

--

2012-05-01  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>

	[BZ #2550]
	[BZ #2570]
	* sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c: Use floating-point
	comparisons to determine direction to adjust input.


diff --git a/sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c b/sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c
index 9ecfef1..350463e 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c
@@ -57,11 +57,7 @@ double __nexttoward(double x, long double y)
 	    return x;
 	}
 	if(hx>=0) {				/* x > 0 */
-	    if (hy<0||(ix>>20)>(iy>>52)
-		|| ((ix>>20)==(iy>>52)
-		    && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
-			|| (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
-			    )))) {	/* x > y, x -= ulp */
+	    if (x > y) {			/* x > 0 */
 		if(lx==0) hx -= 1;
 		lx -= 1;
 	    } else {				/* x < y, x += ulp */
@@ -69,11 +65,7 @@ double __nexttoward(double x, long double y)
 		if(lx==0) hx += 1;
 	    }
 	} else {				/* x < 0 */
-	    if (hy>=0||(ix>>20)>(iy>>52)
-		|| ((ix>>20)==(iy>>52)
-		    && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
-			|| (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
-			   )))) {	/* x < y, x -= ulp */
+	    if (x < y) {			/* x < 0 */
 		if(lx==0) hx -= 1;
 		lx -= 1;
 	    } else {				/* x > y, x += ulp */
-- 
1.6.0.2



-- 
Adhemerval Zanella Netto
  Software Engineer
  Linux Technology Center Brazil
  Toolchain / GLIBC on Power Architecture
  azanella@linux.vnet.ibm.com / azanella@br.ibm.com
  +55 61 8642-9890


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]