about summary refs log tree commit diff
path: root/math
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-31 13:33:18 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-31 13:33:18 +0000
commit32c075e1f01849e161724bbd400ba77244e482cc (patch)
tree5f083a3f352104f32bb6c902d57fa3f294bd8d4d /math
parentd6220e9ee38c1c9285221b023346201ec5f511b3 (diff)
downloadglibc-32c075e1f01849e161724bbd400ba77244e482cc.tar.gz
glibc-32c075e1f01849e161724bbd400ba77244e482cc.tar.xz
glibc-32c075e1f01849e161724bbd400ba77244e482cc.zip
.
Diffstat (limited to 'math')
-rw-r--r--math/atest-exp.c8
-rw-r--r--math/atest-exp2.c7
-rw-r--r--math/atest-sincos.c10
-rw-r--r--math/basic-test.c36
-rw-r--r--math/bug-nextafter.c255
-rw-r--r--math/bug-nexttoward.c255
-rw-r--r--math/libm-test.inc16
-rw-r--r--math/math_private.h6
-rw-r--r--math/s_nextafter.c20
-rw-r--r--math/s_nexttowardf.c21
-rw-r--r--math/test-misc.c74
11 files changed, 658 insertions, 50 deletions
diff --git a/math/atest-exp.c b/math/atest-exp.c
index 2f168c9a6d..158be4231a 100644
--- a/math/atest-exp.c
+++ b/math/atest-exp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Geoffrey Keating <Geoff.Keating@anu.edu.au>, 1997.
 
@@ -171,10 +171,8 @@ main (void)
 
    memset (e2, '\0', sizeof (mp1));
    for (i = -1; i < 100 && i < FRAC / 4; i++)
-     e2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig,
-							     exp1[i + 1])
-						     - hexdig)
- 					<< (FRAC - i * 4 - 4) % mpbpl);
+     e2[(FRAC - i * 4 - 4) / mpbpl] |= ((strchr (hexdig, exp1[i + 1]) - hexdig)
+					<< (FRAC - i * 4 - 4) % mpbpl);
 
    if (mpn_cmp (ex, e2, SZ) >= 0)
      mpn_sub_n (e3, ex, e2, SZ);
diff --git a/math/atest-exp2.c b/math/atest-exp2.c
index 2c028a2b83..33d942fc61 100644
--- a/math/atest-exp2.c
+++ b/math/atest-exp2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Geoffrey Keating <Geoff.Keating@anu.edu.au>, 1997.
 
@@ -73,9 +73,8 @@ read_mpn_hex(mp_limb_t *x, const char *str)
 
   memset (x, 0, sizeof (mp1));
   for (i = -1; i < 100 && i < FRAC / 4; ++i)
-    x[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig, str[i + 1])
-						   - hexdig)
- 				      << (FRAC - i * 4 - 4) % mpbpl);
+    x[(FRAC - i * 4 - 4) / mpbpl] |= ((strchr (hexdig, str[i + 1]) - hexdig)
+				      << (FRAC - i * 4 - 4) % mpbpl);
 }
 
 static mp_limb_t *get_log2(void) __attribute__((const));
diff --git a/math/atest-sincos.c b/math/atest-sincos.c
index bef3521c96..911aaec275 100644
--- a/math/atest-sincos.c
+++ b/math/atest-sincos.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Geoffrey Keating <Geoff.Keating@anu.edu.au>, 1997.
 
@@ -239,11 +239,9 @@ main (void)
    memset (c2, 0, sizeof (mp1));
    for (i = 0; i < 100 && i < FRAC / 4; i++)
      {
-       s2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig, sin1[i])
-						       - hexdig)
- 					  << (FRAC - i * 4 - 4) % mpbpl);
-       c2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig, cos1[i])
-						       - hexdig)
+       s2[(FRAC - i * 4 - 4) / mpbpl] |= ((strchr (hexdig, sin1[i]) - hexdig)
+					  << (FRAC - i * 4 - 4) % mpbpl);
+       c2[(FRAC - i * 4 - 4) / mpbpl] |= ((strchr (hexdig, cos1[i]) - hexdig)
 					  << (FRAC - i * 4 - 4) % mpbpl);
      }
 
diff --git a/math/basic-test.c b/math/basic-test.c
index e42c014572..e48a3ae4e0 100644
--- a/math/basic-test.c
+++ b/math/basic-test.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Jaeger <aj@suse.de>, 1999.
 
@@ -44,7 +44,7 @@ NAME (void)								      \
 									      \
   zero_var = 0.0;							      \
   one_var = 1.0;							      \
-  NaN_var = zero_var/zero_var;						      \
+  NaN_var = zero_var / zero_var;					      \
   Inf_var = one_var / zero_var;						      \
 									      \
   (void) &zero_var;							      \
@@ -103,21 +103,51 @@ NAME (void)								      \
   check (#FLOAT " isinf (-HUGE_VALx) == -1", isinf (x1) == -1);		      \
 }
 
+#define TEST_TRUNC(NAME, FLOAT, DOUBLE) \
+void									      \
+NAME (void)								      \
+{									      \
+  volatile DOUBLE Inf_var, NaN_var, zero_var, one_var;			      \
+  FLOAT x1, x2;								      \
+									      \
+  zero_var = 0.0;							      \
+  one_var = 1.0;							      \
+  NaN_var = zero_var / zero_var;					      \
+  Inf_var = one_var / zero_var;						      \
+									      \
+  (void) &NaN_var;							      \
+  (void) &Inf_var;							      \
+									      \
+  x1 = (FLOAT) NaN_var;							      \
+  check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") NaN", isnan (x1) != 0);	      \
+  x2 = (FLOAT) Inf_var;							      \
+  check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") Inf", isinf (x2) != 0);	      \
+}
+
 TEST_FUNC (float_test, float, nanf, FLT_EPSILON, HUGE_VALF)
 TEST_FUNC (double_test, double, nan, DBL_EPSILON, HUGE_VAL)
+TEST_TRUNC (truncdfsf_test, float, double)
 #ifndef NO_LONG_DOUBLE
 TEST_FUNC (ldouble_test, long double, nanl, LDBL_EPSILON, HUGE_VALL)
+TEST_TRUNC (trunctfsf_test, float, long double)
+TEST_TRUNC (trunctfdf_test, double, long double)
 #endif
 
 int
-main (void)
+do_test (void)
 {
   float_test ();
   double_test ();
+  truncdfsf_test();
 
 #ifndef NO_LONG_DOUBLE
   ldouble_test ();
+  trunctfsf_test();
+  trunctfdf_test();
 #endif
 
   return errors != 0;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/math/bug-nextafter.c b/math/bug-nextafter.c
index 2a967c75bf..1d21841ea6 100644
--- a/math/bug-nextafter.c
+++ b/math/bug-nextafter.c
@@ -4,6 +4,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+float zero = 0.0;
+float inf = INFINITY;
+
 int
 main (void)
 {
@@ -34,6 +37,81 @@ main (void)
       ++result;
     }
 
+  i = 0;
+  m = FLT_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  i = nextafterf (m, i);
+  if (i < 0 || i >= FLT_MIN)
+    {
+      puts ("nextafterf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf+ did not underflow");
+      ++result;
+    }
+  i = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  i = nextafterf (-m, -i);
+  if (i > 0 || i <= -FLT_MIN)
+    {
+      puts ("nextafterf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf- did not underflow");
+      ++result;
+    }
+  i = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  m = nextafterf (zero, inf);
+  if (m < 0.0 || m >= FLT_MIN)
+    {
+      puts ("nextafterf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterf (m, i) != 0.0)
+    {
+      puts ("nextafterf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  m = nextafterf (copysignf (zero, -1.0), -inf);
+  if (m > 0.0 || m <= -FLT_MIN)
+    {
+      puts ("nextafterf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterf (m, -i) != 0.0)
+    {
+      puts ("nextafterf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterf- did not underflow");
+      ++result;
+    }
+
   double di = INFINITY;
   double dm = DBL_MAX;
   feclearexcept (FE_ALL_EXCEPT);
@@ -59,5 +137,182 @@ main (void)
       ++result;
     }
 
+  di = 0;
+  dm = DBL_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  di = nextafter (dm, di);
+  if (di < 0 || di >= DBL_MIN)
+    {
+      puts ("nextafter+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter+ did not underflow");
+      ++result;
+    }
+  di = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  di = nextafter (-dm, -di);
+  if (di > 0 || di <= -DBL_MIN)
+    {
+      puts ("nextafter- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter- did not underflow");
+      ++result;
+    }
+  di = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  dm = nextafter (zero, inf);
+  if (dm < 0.0 || dm >= DBL_MIN)
+    {
+      puts ("nextafter+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafter (dm, di) != 0.0)
+    {
+      puts ("nextafter+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  dm = nextafter (copysign (zero, -1.0), -inf);
+  if (dm > 0.0 || dm <= -DBL_MIN)
+    {
+      puts ("nextafter- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafter (dm, -di) != 0.0)
+    {
+      puts ("nextafter- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafter- did not underflow");
+      ++result;
+    }
+
+#ifndef NO_LONG_DOUBLE
+  long double li = INFINITY;
+  long double lm = LDBL_MAX;
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterl (lm, li) != li)
+    {
+      puts ("nextafterl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_OVERFLOW) == 0)
+    {
+      puts ("nextafterl+ did not overflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterl (-lm, -li) != -li)
+    {
+      puts ("nextafterl failed");
+      ++result;
+    }
+  if (fetestexcept (FE_OVERFLOW) == 0)
+    {
+      puts ("nextafterl- did not overflow");
+      ++result;
+    }
+
+  li = 0;
+  lm = LDBL_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  li = nextafterl (lm, li);
+  if (li < 0 || li >= LDBL_MIN)
+    {
+      puts ("nextafterl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl+ did not underflow");
+      ++result;
+    }
+  li = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  li = nextafterl (-lm, -li);
+  if (li > 0 || li <= -LDBL_MIN)
+    {
+      puts ("nextafterl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl- did not underflow");
+      ++result;
+    }
+  li = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  lm = nextafterl (zero, inf);
+  if (lm < 0.0 || lm >= LDBL_MIN)
+    {
+      puts ("nextafterl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterl (lm, li) != 0.0)
+    {
+      puts ("nextafterl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  lm = nextafterl (copysign (zero, -1.0), -inf);
+  if (lm > 0.0 || lm <= -LDBL_MIN)
+    {
+      puts ("nextafterl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nextafterl (lm, -li) != 0.0)
+    {
+      puts ("nextafterl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nextafterl- did not underflow");
+      ++result;
+    }
+#endif
+
   return result;
 }
diff --git a/math/bug-nexttoward.c b/math/bug-nexttoward.c
index e306a129c2..ff57e5e3f5 100644
--- a/math/bug-nexttoward.c
+++ b/math/bug-nexttoward.c
@@ -4,6 +4,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+float zero = 0.0;
+float inf = INFINITY;
+
 int
 main (void)
 {
@@ -35,6 +38,81 @@ main (void)
       ++result;
     }
 
+  fi = 0;
+  m = FLT_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  fi = nexttowardf (m, fi);
+  if (fi < 0 || fi >= FLT_MIN)
+    {
+      puts ("nexttowardf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf+ did not underflow");
+      ++result;
+    }
+  fi = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  fi = nexttowardf (-m, -fi);
+  if (fi > 0 || fi <= -FLT_MIN)
+    {
+      puts ("nexttowardf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf- did not underflow");
+      ++result;
+    }
+  fi = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  m = nexttowardf (zero, inf);
+  if (m < 0.0 || m >= FLT_MIN)
+    {
+      puts ("nexttowardf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardf (m, fi) != 0.0)
+    {
+      puts ("nexttowardf+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  m = nexttowardf (copysignf (zero, -1.0), -inf);
+  if (m > 0.0 || m <= -FLT_MIN)
+    {
+      puts ("nexttowardf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardf (m, -fi) != 0.0)
+    {
+      puts ("nexttowardf- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardf- did not underflow");
+      ++result;
+    }
+
   tl = (long double) DBL_MAX + 1.0e305L;
   double di = INFINITY;
   double dm = DBL_MAX;
@@ -61,5 +139,182 @@ main (void)
       ++result;
     }
 
+  di = 0;
+  dm = DBL_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  di = nexttoward (dm, di);
+  if (di < 0 || di >= DBL_MIN)
+    {
+      puts ("nexttoward+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward+ did not underflow");
+      ++result;
+    }
+  di = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  di = nexttoward (-dm, -di);
+  if (di > 0 || di <= -DBL_MIN)
+    {
+      puts ("nexttoward- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward- did not underflow");
+      ++result;
+    }
+  di = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  dm = nexttoward (zero, inf);
+  if (dm < 0.0 || dm >= DBL_MIN)
+    {
+      puts ("nexttoward+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttoward (dm, di) != 0.0)
+    {
+      puts ("nexttoward+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  dm = nexttoward (copysign (zero, -1.0), -inf);
+  if (dm > 0.0 || dm <= -DBL_MIN)
+    {
+      puts ("nexttoward- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttoward (dm, -di) != 0.0)
+    {
+      puts ("nexttoward- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttoward- did not underflow");
+      ++result;
+    }
+
+#ifndef NO_LONG_DOUBLE
+  long double li = INFINITY;
+  long double lm = LDBL_MAX;
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardl (lm, li) != li)
+    {
+      puts ("nexttowardl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_OVERFLOW) == 0)
+    {
+      puts ("nexttowardl+ did not overflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardl (-lm, -li) != -li)
+    {
+      puts ("nexttowardl failed");
+      ++result;
+    }
+  if (fetestexcept (FE_OVERFLOW) == 0)
+    {
+      puts ("nexttowardl- did not overflow");
+      ++result;
+    }
+
+  li = 0;
+  lm = LDBL_MIN;
+  feclearexcept (FE_ALL_EXCEPT);
+  li = nexttowardl (lm, li);
+  if (li < 0 || li >= LDBL_MIN)
+    {
+      puts ("nexttowardl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl+ did not underflow");
+      ++result;
+    }
+  li = 0;
+  feclearexcept (FE_ALL_EXCEPT);
+  li = nexttowardl (-lm, -li);
+  if (li > 0 || li <= -LDBL_MIN)
+    {
+      puts ("nexttowardl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl- did not underflow");
+      ++result;
+    }
+  li = -INFINITY;
+  feclearexcept (FE_ALL_EXCEPT);
+  lm = nexttowardl (zero, inf);
+  if (lm < 0.0 || lm >= LDBL_MIN)
+    {
+      puts ("nexttowardl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardl (lm, li) != 0.0)
+    {
+      puts ("nexttowardl+ failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl+ did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  lm = nexttowardl (copysign (zero, -1.0), -inf);
+  if (lm > 0.0 || lm <= -LDBL_MIN)
+    {
+      puts ("nexttowardl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl- did not underflow");
+      ++result;
+    }
+  feclearexcept (FE_ALL_EXCEPT);
+  if (nexttowardl (lm, -li) != 0.0)
+    {
+      puts ("nexttowardl- failed");
+      ++result;
+    }
+  if (fetestexcept (FE_UNDERFLOW) == 0)
+    {
+      puts ("nexttowardl- did not underflow");
+      ++result;
+    }
+#endif
+
   return result;
 }
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 23ee6beaa8..81dd364f77 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -4127,7 +4127,9 @@ log_test (void)
   TEST_f_f (log, 1, 0);
 
   TEST_f_f (log, -1, nan_value, INVALID_EXCEPTION);
+  TEST_f_f (log, minus_infty, nan_value, INVALID_EXCEPTION);
   TEST_f_f (log, plus_infty, plus_infty);
+  TEST_f_f (log, nan_value, nan_value);
 
   TEST_f_f (log, M_El, 1);
   TEST_f_f (log, 1.0 / M_El, -1);
@@ -4157,6 +4159,7 @@ log10_test (void)
 
   /* log10 (x) == NaN plus invalid exception if x < 0.  */
   TEST_f_f (log10, -1, nan_value, INVALID_EXCEPTION);
+  TEST_f_f (log10, minus_infty, nan_value, INVALID_EXCEPTION);
 
   TEST_f_f (log10, plus_infty, plus_infty);
   TEST_f_f (log10, nan_value, nan_value);
@@ -4188,6 +4191,7 @@ log1p_test (void)
 
   TEST_f_f (log1p, -1, minus_infty, DIVIDE_BY_ZERO_EXCEPTION);
   TEST_f_f (log1p, -2, nan_value, INVALID_EXCEPTION);
+  TEST_f_f (log1p, minus_infty, nan_value, INVALID_EXCEPTION);
 
   TEST_f_f (log1p, plus_infty, plus_infty);
   TEST_f_f (log1p, nan_value, nan_value);
@@ -4218,6 +4222,7 @@ log2_test (void)
   TEST_f_f (log2, 1, 0);
 
   TEST_f_f (log2, -1, nan_value, INVALID_EXCEPTION);
+  TEST_f_f (log2, minus_infty, nan_value, INVALID_EXCEPTION);
 
   TEST_f_f (log2, plus_infty, plus_infty);
   TEST_f_f (log2, nan_value, nan_value);
@@ -4614,6 +4619,17 @@ pow_test (void)
 
   /* pow (x, NaN) == NaN.  */
   TEST_ff_f (pow, 3.0, nan_value, nan_value);
+  TEST_ff_f (pow, minus_zero, nan_value, nan_value);
+  TEST_ff_f (pow, plus_infty, nan_value, nan_value);
+  TEST_ff_f (pow, -3.0, nan_value, nan_value);
+  TEST_ff_f (pow, minus_infty, nan_value, nan_value);
+
+  TEST_ff_f (pow, nan_value, 3.0, nan_value);
+  TEST_ff_f (pow, nan_value, -3.0, nan_value);
+  TEST_ff_f (pow, nan_value, plus_infty, nan_value);
+  TEST_ff_f (pow, nan_value, minus_infty, nan_value);
+  TEST_ff_f (pow, nan_value, 2.5, nan_value);
+  TEST_ff_f (pow, nan_value, -2.5, nan_value);
 
   TEST_ff_f (pow, 1, plus_infty, 1);
   TEST_ff_f (pow, -1, plus_infty, 1);
diff --git a/math/math_private.h b/math/math_private.h
index 572e546831..129646f8c5 100644
--- a/math/math_private.h
+++ b/math/math_private.h
@@ -332,4 +332,10 @@ extern double __slowexp (double __x);
 extern double __slowpow (double __x, double __y, double __z);
 extern void __docos (double __x, double __dx, double __v[]);
 
+#ifndef math_opt_barrier
+#define math_opt_barrier(x) \
+({ __typeof (x) __x = x; __asm ("" : "+m" (__x)); __x; })
+#define math_force_eval(x) __asm __volatile ("" : : "m" (x))
+#endif
+
 #endif /* _MATH_PRIVATE_H_ */
diff --git a/math/s_nextafter.c b/math/s_nextafter.c
index 9c678b79c5..d2af52dda3 100644
--- a/math/s_nextafter.c
+++ b/math/s_nextafter.c
@@ -26,7 +26,7 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
 #define nexttoward __internal_nexttoward
 
 #include <math.h>
-#include "math_private.h"
+#include <math_private.h>
 #include <float.h>
 
 #ifdef __STDC__
@@ -49,9 +49,12 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
 	   return x+y;
 	if(x==y) return y;		/* x=y, return y */
 	if((ix|lx)==0) {			/* x == 0 */
+	    double u;
 	    INSERT_WORDS(x,hy&0x80000000,1);	/* return +-minsubnormal */
-	    y = x*x;
-	    if(y==x) return y; else return x;	/* raise underflow flag */
+	    u = math_opt_barrier (x);
+	    u = u*u;
+	    math_force_eval (u);		/* raise underflow flag */
+	    return x;
 	}
 	if(hx>=0) {				/* x > 0 */
 	    if(hx>hy||((hx==hy)&&(lx>ly))) {	/* x > y, x -= ulp */
@@ -74,15 +77,12 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
 	if(hy>=0x7ff00000) {
 	  x = x+x;	/* overflow  */
 	  if (FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1)
-	    asm ("" : "=m"(x) : "m"(x));
+	    asm ("" : "+m"(x));
 	  return x;	/* overflow  */
 	}
-	if(hy<0x00100000) {		/* underflow */
-	    y = x*x;
-	    if(y!=x) {		/* raise underflow flag */
-	        INSERT_WORDS(y,hx,lx);
-		return y;
-	    }
+	if(hy<0x00100000) {
+	    double u = x*x;			/* underflow */
+	    math_force_eval (u);		/* raise underflow flag */
 	}
 	INSERT_WORDS(x,hx,lx);
 	return x;
diff --git a/math/s_nexttowardf.c b/math/s_nexttowardf.c
index 1a1026612e..0494d1a4e9 100644
--- a/math/s_nexttowardf.c
+++ b/math/s_nexttowardf.c
@@ -21,7 +21,7 @@
  */
 
 #include <math.h>
-#include "math_private.h"
+#include <math_private.h>
 #include <float.h>
 
 #ifdef __STDC__
@@ -45,10 +45,12 @@
 	   return x+y;
 	if((long double) x==y) return y;	/* x=y, return y */
 	if(ix==0) {				/* x == 0 */
-	    float x2;
+	    float u;
 	    SET_FLOAT_WORD(x,(u_int32_t)(hy&0x80000000)|1);/* return +-minsub*/
-	    x2 = x*x;
-	    if(x2==x) return x2; else return x; /* raise underflow flag */
+	    u = math_opt_barrier (x);
+	    u = u * u;
+	    math_force_eval (u);		 /* raise underflow flag */
+	    return x;
 	}
 	if(hx>=0) {				/* x > 0 */
 	    if(hy<0||(ix>>23)>(iy>>20)-0x380
@@ -70,15 +72,12 @@
 	  x = x+x;	/* overflow  */
 	  if (FLT_EVAL_METHOD != 0)
 	    /* Force conversion to float.  */
-	    asm ("" : "=m"(x) : "m"(x));
+	    asm ("" : "+m"(x));
 	  return x;
 	}
-	if(hy<0x00800000) {		/* underflow */
-	    float x2 = x*x;
-	    if(x2!=x) {		/* raise underflow flag */
-		SET_FLOAT_WORD(x2,hx);
-		return x2;
-	    }
+	if(hy<0x00800000) {
+	    float u = x*x;			/* underflow */
+	    math_force_eval (u);		/* raise underflow flag */
 	}
 	SET_FLOAT_WORD(x,hx);
 	return x;
diff --git a/math/test-misc.c b/math/test-misc.c
index d2393cc840..862e11f0c3 100644
--- a/math/test-misc.c
+++ b/math/test-misc.c
@@ -1,5 +1,5 @@
 /* Miscellaneous tests which don't fit anywhere else.
-   Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -44,7 +44,6 @@ main (void)
       }
   }
 
-# if __GNUC__ >= 3 || __GNUC_MINOR__ >= 96
   {
     long double x;
     long double m;
@@ -52,17 +51,17 @@ main (void)
     int e;
     int i;
 
-#  if LDBL_MANT_DIG == 64
+# if LDBL_MANT_DIG == 64
     m = 0xf.fffffffffffffffp-4L;
-#  elif LDBL_MANT_DIG == 106
+# elif LDBL_MANT_DIG == 106
     /* This has to match the mantissa of LDBL_MAX which actually does have a
        missing bit in the middle.  */
     m = 0x1.fffffffffffff7ffffffffffff8p-1L;
-#  elif LDBL_MANT_DIG == 113
+# elif LDBL_MANT_DIG == 113
     m = 0x1.ffffffffffffffffffffffffffffp-1L;
-#  else
-#   error "Please adjust"
-#  endif
+# else
+#  error "Please adjust"
+# endif
 
     for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
       {
@@ -106,9 +105,8 @@ main (void)
       }
 
   }
-# endif
 
-#if 0
+# if 0
   {
     int e;
     long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);
@@ -126,7 +124,7 @@ main (void)
 	result = 1;
       }
   }
-#endif
+# endif
 #endif
 
   {
@@ -1183,5 +1181,59 @@ main (void)
     }
 #endif
 
+  volatile float f1 = FLT_MAX;
+  volatile float f2 = FLT_MAX / 2;
+  (void) &f1;
+  (void) &f2;
+  feclearexcept (FE_ALL_EXCEPT);
+  f2 += f1;
+  int fe = fetestexcept (FE_ALL_EXCEPT);
+  if (fe != (FE_OVERFLOW | FE_INEXACT))
+    {
+      printf ("float overflow test failed: %x\n", fe);
+      result = 1;
+    }
+
+  volatile double d1 = DBL_MAX;
+  volatile double d2 = DBL_MAX / 2;
+  (void) &d1;
+  (void) &d2;
+  feclearexcept (FE_ALL_EXCEPT);
+  d2 += d1;
+  fe = fetestexcept (FE_ALL_EXCEPT);
+  if (fe != (FE_OVERFLOW | FE_INEXACT))
+    {
+      printf ("double overflow test failed: %x\n", fe);
+      result = 1;
+    }
+
+#ifndef NO_LONG_DOUBLE
+  volatile long double ld1 = LDBL_MAX;
+  volatile long double ld2 = LDBL_MAX / 2;
+  (void) &ld1;
+  (void) &ld2;
+  feclearexcept (FE_ALL_EXCEPT);
+  ld2 += ld1;
+  fe = fetestexcept (FE_ALL_EXCEPT);
+  if (fe != (FE_OVERFLOW | FE_INEXACT))
+    {
+      printf ("long double overflow test failed: %x\n", fe);
+      result = 1;
+    }
+#endif
+
+#if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
+  volatile long double ld3 = 0x1.0000000000010000000100000001p+1;
+  volatile long double ld4 = 0x1.0000000000000000000000000001p+1;
+  (void) &ld3;
+  (void) &ld4;
+  ld3 -= ld4;
+  if (ld3 != 0x1.0p-47)
+    {
+      printf ("long double subtraction test failed %.28La\n", ld3);
+      result = 1;
+    }
+#endif
+
   return result;
 }