about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-07 03:25:24 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-07 03:25:24 +0000
commit64b02fd2f5fd5d2e2b7187b5e982fa6b59587500 (patch)
tree8b833557f08e0d9088bfbeb20af3389680cdc87f
parent57d20ee7f27850f2c14e7eeb1e64807e6431d469 (diff)
downloadglibc-64b02fd2f5fd5d2e2b7187b5e982fa6b59587500.tar.gz
glibc-64b02fd2f5fd5d2e2b7187b5e982fa6b59587500.tar.xz
glibc-64b02fd2f5fd5d2e2b7187b5e982fa6b59587500.zip
Update.
2003-12-06  Ulrich Drepper  <drepper@redhat.com>

	* math/Makefile (tests): Add bug-nextafter.
	* math/bug-nextafter.c: New file.
	* sysdeps/generic/s_nextafter.c: Construct overflow value correctly.
	* sysdeps/ieee754/flt-32/s_nextafterf.c: Likewise.
	* math/libm-test.inc (nextafter_test): Add test for overflow after
	+/-FLT_MAX etc.
-rw-r--r--ChangeLog9
-rw-r--r--math/Makefile3
-rw-r--r--math/bug-nextafter.c28
-rw-r--r--math/libm-test.inc5
-rw-r--r--sysdeps/generic/s_nextafter.c10
-rw-r--r--sysdeps/ieee754/flt-32/s_nextafterf.c10
6 files changed, 62 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index db3ab6d55e..1bc4afdc3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-12-06  Ulrich Drepper  <drepper@redhat.com>
+
+	* math/Makefile (tests): Add bug-nextafter.
+	* math/bug-nextafter.c: New file.
+	* sysdeps/generic/s_nextafter.c: Construct overflow value correctly.
+	* sysdeps/ieee754/flt-32/s_nextafterf.c: Likewise.
+	* math/libm-test.inc (nextafter_test): Add test for overflow after
+	+/-FLT_MAX etc.
+
 2003-12-04  Steven Munroe  <sjmunroe@us.ibm.com>
 
 	* sysdeps/powerpc/fpu/fgetexcptflg.c (__fegetexceptflag): Add masking
diff --git a/math/Makefile b/math/Makefile
index d04269d298..b8624053a8 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -87,7 +87,8 @@ distribute += $(filter-out $(generated),$(long-m-yes:=.c) $(long-c-yes:=.c))
 
 # Rules for the test suite.
 tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \
-	test-misc test-fpucw tst-definitions test-tgmath test-tgmath-ret
+	test-misc test-fpucw tst-definitions test-tgmath test-tgmath-ret \
+	bug-nextafter
 # We do the `long double' tests only if this data type is available and
 # distinct from `double'.
 test-longdouble-yes = test-ldouble test-ildoubl
diff --git a/math/bug-nextafter.c b/math/bug-nextafter.c
new file mode 100644
index 0000000000..8aa849df19
--- /dev/null
+++ b/math/bug-nextafter.c
@@ -0,0 +1,28 @@
+#include <math.h>
+#include <float.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+  int result = 0;
+
+  float i = INFINITY;
+  float m = FLT_MAX;
+  if (nextafterf (m, i) != i)
+    {
+      puts ("nextafterf failed");
+      ++result;
+    }
+
+  double di = INFINITY;
+  double dm = DBL_MAX;
+  if (nextafter (dm, di) != di)
+    {
+      puts ("nextafter failed");
+      ++result;
+    }
+
+  return result;
+}
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 69752e00d5..38386c1ed5 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -3437,6 +3437,11 @@ nextafter_test (void)
   TEST_ff_f (nextafter, 1.1L, nan_value, nan_value);
   TEST_ff_f (nextafter, nan_value, nan_value, nan_value);
 
+  FLOAT fltmax = CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX,
+			 LDBL_MAX, DBL_MAX, FLT_MAX);
+  TEST_ff_f (nextafter, fltmax, plus_infty, plus_infty);
+  TEST_ff_f (nextafter, -fltmax, minus_infty, minus_infty);
+
 #ifdef TEST_LDOUBLE
   // XXX Enable once gcc is fixed.
   //TEST_ff_f (nextafter, 0x0.00000040000000000000p-16385L, -0.1L, 0x0.0000003ffffffff00000p-16385L);
diff --git a/sysdeps/generic/s_nextafter.c b/sysdeps/generic/s_nextafter.c
index a016ab0a4d..9290fc6568 100644
--- a/sysdeps/generic/s_nextafter.c
+++ b/sysdeps/generic/s_nextafter.c
@@ -27,6 +27,7 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
 
 #include "math.h"
 #include "math_private.h"
+#include <float.h>
 
 #ifdef __STDC__
 	double __nextafter(double x, double y)
@@ -70,7 +71,14 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
 	    }
 	}
 	hy = hx&0x7ff00000;
-	if(hy>=0x7ff00000) return x+x;	/* overflow  */
+	if(hy>=0x7ff00000) {
+#if FLT_EVAL_METHOD == 0 || FLT_EVAL_METHOD == 1
+	  return x+x;	/* overflow  */
+#else
+	  /* Note that y is either +Inf or -Inf.  */
+	  return x+y;
+#endif
+	}
 	if(hy<0x00100000) {		/* underflow */
 	    y = x*x;
 	    if(y!=x) {		/* raise underflow flag */
diff --git a/sysdeps/ieee754/flt-32/s_nextafterf.c b/sysdeps/ieee754/flt-32/s_nextafterf.c
index 611742bdf4..e144e56acd 100644
--- a/sysdeps/ieee754/flt-32/s_nextafterf.c
+++ b/sysdeps/ieee754/flt-32/s_nextafterf.c
@@ -19,6 +19,7 @@ static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp
 
 #include "math.h"
 #include "math_private.h"
+#include <float.h>
 
 #ifdef __STDC__
 	float __nextafterf(float x, float y)
@@ -57,7 +58,14 @@ static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp
 	    }
 	}
 	hy = hx&0x7f800000;
-	if(hy>=0x7f800000) return x+x;	/* overflow  */
+	if(hy>=0x7f800000) {
+#if FLT_EVAL_METHOD == 0
+	  return x+x;	/* overflow  */
+#else
+	  /* Note that y is either +Inf or -Inf.  */
+	  return x+y;
+#endif
+	}
 	if(hy<0x00800000) {		/* underflow */
 	    y = x*x;
 	    if(y!=x) {		/* raise underflow flag */