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 Tuesday, May 01, 2012 22:40:22 Adhemerval Zanella wrote:
> 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.


Thanks, this is fine. Shall I commit it on your behalf?

Andreas

> 
> 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 */

-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


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