This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix remainder (NaN, 0)
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Thu, 29 Sep 2011 11:33:15 +0200
- Subject: Fix remainder (NaN, 0)
We handled a corner case wrong, here's a patch.
Andreas
2011-09-29 Andreas Jaeger <aj@suse.de>
[BZ#6779]
* math/w_remainderl.c (__remainderl): Handle (NaN, 0) correctly.
* math/w_remainder.c (__remainder): Likewise.
* math/w_remainderf.c (__remainderf): Likewise.
* math/libm-test.inc (remainder_test): Add test case.
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 70d936c..8503e30 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -4945,6 +4945,10 @@ remainder_test (void)
TEST_ff_f (remainder, plus_infty, 1, nan_value, INVALID_EXCEPTION);
TEST_ff_f (remainder, minus_infty, 1, nan_value, INVALID_EXCEPTION);
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..716491e 100644
--- a/math/w_remainder.c
+++ b/math/w_remainder.c
@@ -33,7 +33,7 @@ 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(_LIB_VERSION == _IEEE_ || __isnan(y) || __isnan(x)) return z;
if(y==0.0)
return __kernel_standard(x,y,28); /* remainder(x,0) */
else
diff --git a/math/w_remainderf.c b/math/w_remainderf.c
index 486e626..a502544 100644
--- a/math/w_remainderf.c
+++ b/math/w_remainderf.c
@@ -36,7 +36,7 @@ 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(_LIB_VERSION == _IEEE_ || __isnanf(y) || __isnanf(x)) return z;
if(y==(float)0.0)
/* remainder(x,0) */
return (float)__kernel_standard((double)x,(double)y,128);
diff --git a/math/w_remainderl.c b/math/w_remainderl.c
index 7635fb9..7a3f267 100644
--- a/math/w_remainderl.c
+++ b/math/w_remainderl.c
@@ -38,7 +38,7 @@ static char rcsid[] = "$NetBSD: $";
#else
long double z;
z = __ieee754_remainderl(x,y);
- if(_LIB_VERSION == _IEEE_ || __isnanl(y)) return z;
+ if(_LIB_VERSION == _IEEE_ || __isnanl(y) || __isnanl(x)) return z;
if(y==0.0)
return __kernel_standard(x,y,228); /* remainder(x,0) */
else
--
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