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 remainder (NaN, 0)


On Thursday, September 29, 2011 11:33:15 Andreas Jaeger wrote:
> We handled a corner case wrong, here's a patch.

There was one more bug, so here's an updated patch,

Andreas

2011-09-29  Andreas Jaeger  <aj@suse.de>

	[BZ#6779,6783]
	* math/w_remainderl.c (__remainderl): Handle (NaN, 0) and (Inf,y)
	correctly. 
	* math/w_remainder.c (__remainder): Likewise.
	* math/w_remainderf.c (__remainderf): Likewise.
	* math/libm-test.inc (remainder_test): Add test cases.

diff --git a/math/libm-test.inc b/math/libm-test.inc
index 70d936c..5d2b6f4 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -4940,11 +4940,21 @@ remainder_test (void)
 
   START (remainder);
 
+  errno = 0;
   TEST_ff_f (remainder, 1, 0, nan_value, INVALID_EXCEPTION);
+  check_int ("errno for remainder(1, 0) =EDOM ", errno, EDOM, 0, 0, 0);
   TEST_ff_f (remainder, 1, minus_zero, nan_value, INVALID_EXCEPTION);
+  errno = 0;
   TEST_ff_f (remainder, plus_infty, 1, nan_value, INVALID_EXCEPTION);
+  check_int ("errno for remainder(+Inf, 1) =EDOM ", errno, EDOM, 0, 0, 0);
+  errno = 0;
   TEST_ff_f (remainder, minus_infty, 1, nan_value, INVALID_EXCEPTION);
+  check_int ("errno for remainder(-Inf, 1) =EDOM ", errno, EDOM, 0, 0, 0);
   TEST_ff_f (remainder, nan_value, nan_value, nan_value);
+  TEST_ff_f (remainder, 0, nan_value, nan_value);
+  errno = 0;
+  TEST_ff_f (remainder, nan_value, 0, nan_value);
+  check_int ("errno for remainder(NaN, 0) unchanged", errno, 0, 0, 0, 0);
 
   TEST_ff_f (remainder, 1.625, 1.0, -0.375);
   TEST_ff_f (remainder, -1.625, 1.0, 0.375);
diff --git a/math/w_remainder.c b/math/w_remainder.c
index 9d7a7c5..9ff53e3 100644
--- a/math/w_remainder.c
+++ b/math/w_remainder.c
@@ -33,8 +33,8 @@ static char rcsid[] = "$NetBSD: w_remainder.c,v 1.6 
1995/05/10 20:49:44 jtc Exp
 #else
 	double z;
 	z = __ieee754_remainder(x,y);
-	if(_LIB_VERSION == _IEEE_ || __isnan(y)) return z;
-	if(y==0.0)
+	if(_LIB_VERSION == _IEEE_ || __isnan(y) || __isnan(x)) return z;
+	if(y==0.0 || __isinf(x))
 	    return __kernel_standard(x,y,28); /* remainder(x,0) */
 	else
 	    return z;
diff --git a/math/w_remainderf.c b/math/w_remainderf.c
index 486e626..b2b568f 100644
--- a/math/w_remainderf.c
+++ b/math/w_remainderf.c
@@ -36,8 +36,8 @@ static char rcsid[] = "$NetBSD: w_remainderf.c,v 1.3 
1995/05/10 20:49:46 jtc Exp
 #else
 	float z;
 	z = __ieee754_remainderf(x,y);
-	if(_LIB_VERSION == _IEEE_ || __isnanf(y)) return z;
-	if(y==(float)0.0) 
+	if(_LIB_VERSION == _IEEE_ || __isnanf(y) || __isnanf(x)) return z;
+	if(y==(float)0.0  || __isinff(x)) 
 	    /* remainder(x,0) */
 	    return (float)__kernel_standard((double)x,(double)y,128);
 	else
diff --git a/math/w_remainderl.c b/math/w_remainderl.c
index 7635fb9..68a5335 100644
--- a/math/w_remainderl.c
+++ b/math/w_remainderl.c
@@ -38,8 +38,8 @@ static char rcsid[] = "$NetBSD: $";
 #else
 	long double z;
 	z = __ieee754_remainderl(x,y);
-	if(_LIB_VERSION == _IEEE_ || __isnanl(y)) return z;
-	if(y==0.0)
+	if(_LIB_VERSION == _IEEE_ || __isnanl(y) || __isnanl(x)) return z;
+	if(y==0.0  || __isinfl(x))
 	    return __kernel_standard(x,y,228); /* remainder(x,0) */
 	else
 	    return z;

-- 
 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, HRB 16746 (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]