exp2* tests: More tests.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2012 14:45:46 +0000 (15:45 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2012 22:20:59 +0000 (23:20 +0100)
* tests/test-exp2.h (test_function): Test all integral arguments that
don't need to overflow or denormalized numbers.
* tests/test-exp2.c (MAX_EXP, MIN_EXP): New macros.
* tests/test-exp2f.c (MAX_EXP, MIN_EXP): Likewise.
* tests/test-exp2l.c (MAX_EXP, MIN_EXP): Likewise.

ChangeLog
tests/test-exp2.c
tests/test-exp2.h
tests/test-exp2f.c
tests/test-exp2l.c

index 0b86a60..055f255 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-03-11  Bruno Haible  <bruno@clisp.org>
+
+       exp2* tests: More tests.
+       * tests/test-exp2.h (test_function): Test all integral arguments that
+       don't need to overflow or denormalized numbers.
+       * tests/test-exp2.c (MAX_EXP, MIN_EXP): New macros.
+       * tests/test-exp2f.c (MAX_EXP, MIN_EXP): Likewise.
+       * tests/test-exp2l.c (MAX_EXP, MIN_EXP): Likewise.
+
 2012-03-10  Bruno Haible  <bruno@clisp.org>
 
        log1pl-ieee: Work around test failure on AIX 7.1.
index b59a9a6..0140d40 100644 (file)
@@ -30,6 +30,8 @@ SIGNATURE_CHECK (exp2, double, (double));
 #define DOUBLE double
 #define L_(literal) literal
 #define MANT_DIG DBL_MANT_DIG
+#define MAX_EXP DBL_MAX_EXP
+#define MIN_EXP DBL_MIN_EXP
 #define EXP2 exp2
 #define RANDOM randomd
 #include "test-exp2.h"
index f342603..7a6bb1e 100644 (file)
@@ -29,45 +29,41 @@ test_function (void)
     * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
     * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
 
-  /* Small integral arguments.  */
+  /* Integral arguments.  */
   {
     DOUBLE x = L_(0.0);
     DOUBLE y = EXP2 (x);
     ASSERT (y == L_(1.0));
   }
-  {
-    DOUBLE x = L_(1.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(2.0));
-  }
-  {
-    DOUBLE x = L_(2.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(4.0));
-  }
   /* <http://sourceware.org/bugzilla/show_bug.cgi?id=13824> */
-#if !(defined __linux__ && defined __sparc__)
+#if !(defined __linux__ && (defined __sparc__ || defined __powerpc__))
   {
-    DOUBLE x = L_(3.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(8.0));
+    int e;
+    DOUBLE x;
+    DOUBLE y;
+    for (e = 0, x = L_(0.0), y = L_(1.0);
+         e <= MAX_EXP - 1;
+         e++, x = x + L_(1.0), y = y * L_(2.0))
+      {
+        /* Invariant: x = e, y = 2^e.  */
+        DOUBLE z = EXP2 (x);
+        ASSERT (z == y);
+      }
   }
   {
-    DOUBLE x = L_(4.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(16.0));
+    int e;
+    DOUBLE x;
+    DOUBLE y;
+    for (e = 0, x = L_(0.0), y = L_(1.0);
+         e >= MIN_EXP - 1;
+         e--, x = x - L_(1.0), y = y * L_(0.5))
+      {
+        /* Invariant: x = e, y = 2^e.  */
+        DOUBLE z = EXP2 (x);
+        ASSERT (z == y);
+      }
   }
 #endif
-  {
-    DOUBLE x = - L_(1.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(0.5));
-  }
-  {
-    DOUBLE x = - L_(2.0);
-    DOUBLE y = EXP2 (x);
-    ASSERT (y == L_(0.25));
-  }
 
   /* Randomized tests.  */
   {
index 5d1e5d3..5e51737 100644 (file)
@@ -30,6 +30,8 @@ SIGNATURE_CHECK (exp2f, float, (float));
 #define DOUBLE float
 #define L_(literal) literal##f
 #define MANT_DIG FLT_MANT_DIG
+#define MAX_EXP FLT_MAX_EXP
+#define MIN_EXP FLT_MIN_EXP
 #define EXP2 exp2f
 #define RANDOM randomf
 #include "test-exp2.h"
index eb8bb38..9a2ef78 100644 (file)
@@ -31,6 +31,8 @@ SIGNATURE_CHECK (exp2l, long double, (long double));
 #define DOUBLE long double
 #define L_(literal) literal##L
 #define MANT_DIG LDBL_MANT_DIG
+#define MAX_EXP LDBL_MAX_EXP
+#define MIN_EXP LDBL_MIN_EXP
 #define EXP2 exp2l
 #define RANDOM randoml
 #include "test-exp2.h"