Refactor frexp*-ieee tests.
authorBruno Haible <bruno@clisp.org>
Sun, 26 Feb 2012 15:19:59 +0000 (16:19 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 26 Feb 2012 15:19:59 +0000 (16:19 +0100)
* tests/test-frexp-ieee.h: New file.
* tests/test-frexpf-ieee.c: Include test-frexp-ieee.h.
(main): Just call test_function.
* tests/test-frexp-ieee.c: Include test-frexp-ieee.h.
(main): Just call test_function.
* tests/test-frexpl-ieee.c: Include test-frexp-ieee.h.
(main): Just call test_function.
* modules/frexpf-ieee-tests (Files): Add tests/test-frexp-ieee.h.
* modules/frexp-ieee-tests (Files): Likewise.
* modules/frexpl-ieee-tests (Files): Likewise.

ChangeLog
modules/frexp-ieee-tests
modules/frexpf-ieee-tests
modules/frexpl-ieee-tests
tests/test-frexp-ieee.c
tests/test-frexp-ieee.h [new file with mode: 0644]
tests/test-frexpf-ieee.c
tests/test-frexpl-ieee.c

index f08dfd8..cb19d9f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2012-02-26  Bruno Haible  <bruno@clisp.org>
 
+       Refactor frexp*-ieee tests.
+       * tests/test-frexp-ieee.h: New file.
+       * tests/test-frexpf-ieee.c: Include test-frexp-ieee.h.
+       (main): Just call test_function.
+       * tests/test-frexp-ieee.c: Include test-frexp-ieee.h.
+       (main): Just call test_function.
+       * tests/test-frexpl-ieee.c: Include test-frexp-ieee.h.
+       (main): Just call test_function.
+       * modules/frexpf-ieee-tests (Files): Add tests/test-frexp-ieee.h.
+       * modules/frexp-ieee-tests (Files): Likewise.
+       * modules/frexpl-ieee-tests (Files): Likewise.
+
        Tests for module 'frexpl-ieee'.
        * modules/frexpl-ieee-tests: New file.
        * tests/test-frexpl-ieee.c: New file.
index e3774f5..c055d52 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-frexp-ieee.c
+tests/test-frexp-ieee.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
index ca8d7eb..19fb494 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-frexpf-ieee.c
+tests/test-frexp-ieee.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
index 9e0fa39..bd19689 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-frexpl-ieee.c
+tests/test-frexp-ieee.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
index 258d1dd..72678e9 100644 (file)
 #include "nan.h"
 #include "macros.h"
 
+#undef INFINITY
+#undef NAN
+
+#define DOUBLE double
+#define ISNAN isnand
+#define INFINITY Infinityd ()
+#define NAN NaNd ()
+#define L_(literal) literal
+#define MINUS_ZERO minus_zerod
+#define FREXP frexp
+#include "test-frexp-ieee.h"
+
 int
 main ()
 {
-  /* [MX] shaded specification in POSIX.  */
-
-  /* NaN.  */
-  {
-    int exp = -9999;
-    double mantissa;
-    mantissa = frexp (NaNd (), &exp);
-    ASSERT (isnand (mantissa));
-  }
-
-  /* Signed zero.  */
-  {
-    int exp = -9999;
-    double mantissa;
-    mantissa = frexp (0.0, &exp);
-    ASSERT (mantissa == 0.0);
-    ASSERT (!signbit (mantissa));
-    ASSERT (exp == 0);
-  }
-  {
-    int exp = -9999;
-    double mantissa;
-    mantissa = frexp (minus_zerod, &exp);
-    ASSERT (mantissa == 0.0);
-    ASSERT (!!signbit (mantissa) == !!signbit (minus_zerod));
-    ASSERT (exp == 0);
-  }
-
-  /* Infinity.  */
-  {
-    int exp = -9999;
-    double mantissa;
-    mantissa = frexp (Infinityd (), &exp);
-    ASSERT (mantissa == Infinityd ());
-  }
-  {
-    int exp = -9999;
-    double mantissa;
-    mantissa = frexp (- Infinityd (), &exp);
-    ASSERT (mantissa == - Infinityd ());
-  }
+  test_function ();
 
   return 0;
 }
diff --git a/tests/test-frexp-ieee.h b/tests/test-frexp-ieee.h
new file mode 100644 (file)
index 0000000..83893b0
--- /dev/null
@@ -0,0 +1,61 @@
+/* Test of splitting a double into fraction and mantissa.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static void
+test_function (void)
+{
+  /* [MX] shaded specification in POSIX.  */
+
+  /* NaN.  */
+  {
+    int exp = -9999;
+    DOUBLE mantissa;
+    mantissa = FREXP (NAN, &exp);
+    ASSERT (ISNAN (mantissa));
+  }
+
+  /* Signed zero.  */
+  {
+    int exp = -9999;
+    DOUBLE mantissa;
+    mantissa = FREXP (L_(0.0), &exp);
+    ASSERT (mantissa == L_(0.0));
+    ASSERT (!signbit (mantissa));
+    ASSERT (exp == 0);
+  }
+  {
+    int exp = -9999;
+    DOUBLE mantissa;
+    mantissa = FREXP (MINUS_ZERO, &exp);
+    ASSERT (mantissa == L_(0.0));
+    ASSERT (!!signbit (mantissa) == !!signbit (MINUS_ZERO));
+    ASSERT (exp == 0);
+  }
+
+  /* Infinity.  */
+  {
+    int exp = -9999;
+    DOUBLE mantissa;
+    mantissa = FREXP (INFINITY, &exp);
+    ASSERT (mantissa == INFINITY);
+  }
+  {
+    int exp = -9999;
+    DOUBLE mantissa;
+    mantissa = FREXP (- INFINITY, &exp);
+    ASSERT (mantissa == - INFINITY);
+  }
+}
index ea32ea9..cbecc1f 100644 (file)
 #include "nan.h"
 #include "macros.h"
 
+#undef INFINITY
+#undef NAN
+
+#define DOUBLE float
+#define ISNAN isnanf
+#define INFINITY Infinityf ()
+#define NAN NaNf ()
+#define L_(literal) literal##f
+#define MINUS_ZERO minus_zerof
+#define FREXP frexpf
+#include "test-frexp-ieee.h"
+
 int
 main ()
 {
-  /* [MX] shaded specification in POSIX.  */
-
-  /* NaN.  */
-  {
-    int exp = -9999;
-    float mantissa;
-    mantissa = frexpf (NaNf (), &exp);
-    ASSERT (isnanf (mantissa));
-  }
-
-  /* Signed zero.  */
-  {
-    int exp = -9999;
-    float mantissa;
-    mantissa = frexpf (0.0f, &exp);
-    ASSERT (mantissa == 0.0f);
-    ASSERT (!signbit (mantissa));
-    ASSERT (exp == 0);
-  }
-  {
-    int exp = -9999;
-    float mantissa;
-    mantissa = frexpf (minus_zerof, &exp);
-    ASSERT (mantissa == 0.0f);
-    ASSERT (!!signbit (mantissa) == !!signbit (minus_zerof));
-    ASSERT (exp == 0);
-  }
-
-  /* Infinity.  */
-  {
-    int exp = -9999;
-    float mantissa;
-    mantissa = frexpf (Infinityf (), &exp);
-    ASSERT (mantissa == Infinityf ());
-  }
-  {
-    int exp = -9999;
-    float mantissa;
-    mantissa = frexpf (- Infinityf (), &exp);
-    ASSERT (mantissa == - Infinityf ());
-  }
+  test_function ();
 
   return 0;
 }
index c9fae56..1afc7e2 100644 (file)
 #include "nan.h"
 #include "macros.h"
 
+#undef INFINITY
+#undef NAN
+
+#define DOUBLE long double
+#define ISNAN isnanl
+#define INFINITY Infinityl ()
+#define NAN NaNl ()
+#define L_(literal) literal##L
+#define MINUS_ZERO minus_zerol
+#define FREXP frexpl
+#include "test-frexp-ieee.h"
+
 int
 main ()
 {
-  /* [MX] shaded specification in POSIX.  */
-
-  /* NaN.  */
-  {
-    int exp = -9999;
-    long double mantissa;
-    mantissa = frexpl (NaNl (), &exp);
-    ASSERT (isnanl (mantissa));
-  }
-
-  /* Signed zero.  */
-  {
-    int exp = -9999;
-    long double mantissa;
-    mantissa = frexpl (0.0L, &exp);
-    ASSERT (mantissa == 0.0L);
-    ASSERT (!signbit (mantissa));
-    ASSERT (exp == 0);
-  }
-  {
-    int exp = -9999;
-    long double mantissa;
-    mantissa = frexpl (minus_zerol, &exp);
-    ASSERT (mantissa == 0.0L);
-    ASSERT (!!signbit (mantissa) == !!signbit (minus_zerol));
-    ASSERT (exp == 0);
-  }
-
-  /* Infinity.  */
-  {
-    int exp = -9999;
-    long double mantissa;
-    mantissa = frexpl (Infinityl (), &exp);
-    ASSERT (mantissa == Infinityl ());
-  }
-  {
-    int exp = -9999;
-    long double mantissa;
-    mantissa = frexpl (- Infinityl (), &exp);
-    ASSERT (mantissa == - Infinityl ());
-  }
+  test_function ();
 
   return 0;
 }