changeset 16046:16310a975709

ldexp, ldexpf, ldexpl: Enhance tests. * tests/test-ldexp.h: New file, combining code from tests/test-ldexp.c and tests/test-ldexpl.c. * tests/test-ldexpl.c: (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (main): Just call test_function. * tests/test-ldexp.c: Include float.h, isnand-nolibm.h, minus-zero.h, infinity.h, nan.h. (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (x, y): Remove variables. (main): Just call test_function. * tests/test-ldexpf.c: Include float.h, isnanf-nolibm.h, minus-zero.h, infinity.h, nan.h. (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (x, y): Remove variables. (main): Just call test_function. * modules/ldexpl-tests (Files): Add tests/test-ldexp.h. * modules/ldexp-tests (Files): Add tests/test-ldexp.h, tests/minus-zero.h, tests/infinity.h, tests/nan.h. (Depends-on): Add isnand-nolibm, signbit, float. * modules/ldexpf-tests (Files): Add tests/test-ldexp.h, tests/minus-zero.h, tests/infinity.h, tests/nan.h. (Depends-on): Add isnanf-nolibm, signbit, float.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 Nov 2011 13:52:30 +0100
parents 708181030fbc
children 843e85c12830
files ChangeLog modules/ldexp-tests modules/ldexpf-tests modules/ldexpl-tests tests/test-ldexp.c tests/test-ldexp.h tests/test-ldexpf.c tests/test-ldexpl.c
diffstat 8 files changed, 222 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2011-11-06  Bruno Haible  <bruno@clisp.org>
+
+	ldexp, ldexpf, ldexpl: Enhance tests.
+	* tests/test-ldexp.h: New file, combining code from tests/test-ldexp.c
+	and tests/test-ldexpl.c.
+	* tests/test-ldexpl.c: (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO,
+	LDEXP, MIN_EXP, MAX_EXP): New macros.
+	Include test-ldexp.h.
+	(main): Just call test_function.
+	* tests/test-ldexp.c: Include float.h, isnand-nolibm.h, minus-zero.h,
+	infinity.h, nan.h.
+	(DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP,
+	MAX_EXP): New macros.
+	Include test-ldexp.h.
+	(x, y): Remove variables.
+	(main): Just call test_function.
+	* tests/test-ldexpf.c: Include float.h, isnanf-nolibm.h, minus-zero.h,
+	infinity.h, nan.h.
+	(DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP,
+	MAX_EXP): New macros.
+	Include test-ldexp.h.
+	(x, y): Remove variables.
+	(main): Just call test_function.
+	* modules/ldexpl-tests (Files): Add tests/test-ldexp.h.
+	* modules/ldexp-tests (Files): Add tests/test-ldexp.h,
+	tests/minus-zero.h, tests/infinity.h, tests/nan.h.
+	(Depends-on): Add isnand-nolibm, signbit, float.
+	* modules/ldexpf-tests (Files): Add tests/test-ldexp.h,
+	tests/minus-zero.h, tests/infinity.h, tests/nan.h.
+	(Depends-on): Add isnanf-nolibm, signbit, float.
+
 2011-11-06  Bruno Haible  <bruno@clisp.org>
 
 	math tests: Cosmetics.
--- a/modules/ldexp-tests
+++ b/modules/ldexp-tests
@@ -1,9 +1,16 @@
 Files:
 tests/test-ldexp.c
+tests/test-ldexp.h
+tests/minus-zero.h
+tests/infinity.h
+tests/nan.h
 tests/signature.h
 tests/macros.h
 
 Depends-on:
+isnand-nolibm
+signbit
+float
 
 configure.ac:
 
--- a/modules/ldexpf-tests
+++ b/modules/ldexpf-tests
@@ -1,9 +1,16 @@
 Files:
 tests/test-ldexpf.c
+tests/test-ldexp.h
+tests/minus-zero.h
+tests/infinity.h
+tests/nan.h
 tests/signature.h
 tests/macros.h
 
 Depends-on:
+isnanf-nolibm
+signbit
+float
 
 configure.ac:
 
--- a/modules/ldexpl-tests
+++ b/modules/ldexpl-tests
@@ -1,5 +1,6 @@
 Files:
 tests/test-ldexpl.c
+tests/test-ldexp.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
--- a/tests/test-ldexp.c
+++ b/tests/test-ldexp.c
@@ -1,5 +1,5 @@
 /* Test of ldexp() function.
-   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+   Copyright (C) 2007-2011 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
@@ -14,7 +14,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
+/* Written by Bruno Haible <bruno@clisp.org>, 2007, 2010.  */
 
 #include <config.h>
 
@@ -23,26 +23,32 @@
 #include "signature.h"
 SIGNATURE_CHECK (ldexp, double, (double, int));
 
+#include <float.h>
+
+#include "isnand-nolibm.h"
+#include "minus-zero.h"
+#include "infinity.h"
+#include "nan.h"
 #include "macros.h"
 
-volatile double x;
-double y;
+#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 LDEXP ldexp
+#define MIN_EXP DBL_MIN_EXP
+#define MAX_EXP DBL_MAX_EXP
+#include "test-ldexp.h"
 
 int
 main ()
 {
-  /* A particular value.  */
-  x = 0.6;
-  y = ldexp (x, 0);
-  ASSERT (y >= 0.5999999999 && y <= 0.6000000001);
-
-  x = 0.6;
-  y = ldexp (x, 1);
-  ASSERT (y >= 1.199999999 && y <= 1.200000001);
-
-  x = 0.6;
-  y = ldexp (x, -1);
-  ASSERT (y >= 0.2999999999 && y <= 0.3000000001);
+  test_function ();
 
   return 0;
 }
new file mode 100644
--- /dev/null
+++ b/tests/test-ldexp.h
@@ -0,0 +1,117 @@
+/* Test of ldexp*() function family.
+   Copyright (C) 2007-2011 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/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007, 2010.  */
+
+static void
+test_function (void)
+{
+  int i;
+  volatile DOUBLE x;
+  volatile DOUBLE y;
+
+  /* A particular value.  */
+  {
+    x = L_(0.6);
+    y = LDEXP (x, 0);
+    ASSERT (y >= L_(0.5999999999) && y <= L_(0.6000000001));
+  }
+  {
+    x = L_(0.6);
+    y = LDEXP (x, 1);
+    ASSERT (y >= L_(1.199999999) && y <= L_(1.200000001));
+  }
+  {
+    x = L_(0.6);
+    y = LDEXP (x, -1);
+    ASSERT (y >= L_(0.2999999999) && y <= L_(0.3000000001));
+  }
+
+  { /* NaN.  */
+    x = NAN;
+    y = LDEXP (x, 0); ASSERT (ISNAN (y));
+    y = LDEXP (x, 5); ASSERT (ISNAN (y));
+    y = LDEXP (x, -5); ASSERT (ISNAN (y));
+  }
+
+  { /* Positive infinity.  */
+    x = INFINITY;
+    y = LDEXP (x, 0); ASSERT (y == x);
+    y = LDEXP (x, 5); ASSERT (y == x);
+    y = LDEXP (x, -5); ASSERT (y == x);
+  }
+
+  { /* Negative infinity.  */
+    x = - INFINITY;
+    y = LDEXP (x, 0); ASSERT (y == x);
+    y = LDEXP (x, 5); ASSERT (y == x);
+    y = LDEXP (x, -5); ASSERT (y == x);
+  }
+
+  { /* Positive zero.  */
+    x = L_(0.0);
+    y = LDEXP (x, 0); ASSERT (y == x); ASSERT (!signbit (x));
+    y = LDEXP (x, 5); ASSERT (y == x); ASSERT (!signbit (x));
+    y = LDEXP (x, -5); ASSERT (y == x); ASSERT (!signbit (x));
+  }
+
+  { /* Negative zero.  */
+    x = MINUS_ZERO;
+    y = LDEXP (x, 0); ASSERT (y == x); ASSERT (signbit (x));
+    y = LDEXP (x, 5); ASSERT (y == x); ASSERT (signbit (x));
+    y = LDEXP (x, -5); ASSERT (y == x); ASSERT (signbit (x));
+  }
+
+  { /* Positive finite number.  */
+    x = L_(1.73205);
+    y = LDEXP (x, 0); ASSERT (y == x);
+    y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
+    y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
+  }
+
+  { /* Negative finite number.  */
+    x = - L_(20.085536923187667742);
+    y = LDEXP (x, 0); ASSERT (y == x);
+    y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
+    y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
+  }
+
+  for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0))
+    {
+      y = LDEXP (x, 0); ASSERT (y == x);
+      {
+        volatile DOUBLE expected;
+        y = LDEXP (x, 5);
+        expected = x * L_(32.0);
+        ASSERT (y == expected);
+      }
+      y = LDEXP (x, -5); ASSERT (y == x * 0.03125L);
+    }
+  for (i = 1, x = L_(1.73205); i >= MIN_EXP; i--, x *= L_(0.5))
+    {
+      y = LDEXP (x, 0); ASSERT (y == x);
+      y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
+      if (i - 5 >= MIN_EXP)
+        {
+          y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
+        }
+    }
+  for (; i >= LDBL_MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
+    {
+      y = LDEXP (x, 0); ASSERT (y == x);
+      y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
+    }
+}
--- a/tests/test-ldexpf.c
+++ b/tests/test-ldexpf.c
@@ -1,5 +1,5 @@
 /* Test of ldexpf() function.
-   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+   Copyright (C) 2007-2011 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
@@ -14,7 +14,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
+/* Written by Bruno Haible <bruno@clisp.org>, 2007, 2010.  */
 
 #include <config.h>
 
@@ -23,26 +23,32 @@
 #include "signature.h"
 SIGNATURE_CHECK (ldexpf, float, (float, int));
 
+#include <float.h>
+
+#include "isnanf-nolibm.h"
+#include "minus-zero.h"
+#include "infinity.h"
+#include "nan.h"
 #include "macros.h"
 
-volatile float x;
-float y;
+#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 LDEXP ldexpf
+#define MIN_EXP FLT_MIN_EXP
+#define MAX_EXP FLT_MAX_EXP
+#include "test-ldexp.h"
 
 int
 main ()
 {
-  /* A particular value.  */
-  x = 0.6f;
-  y = ldexp (x, 0);
-  ASSERT (y >= 0.59999999f && y <= 0.60000001f);
-
-  x = 0.6f;
-  y = ldexp (x, 1);
-  ASSERT (y >= 1.1999999f && y <= 1.2000001f);
-
-  x = 0.6f;
-  y = ldexp (x, -1);
-  ASSERT (y >= 0.29999999f && y <= 0.30000001f);
+  test_function ();
 
   return 0;
 }
--- a/tests/test-ldexpl.c
+++ b/tests/test-ldexpl.c
@@ -32,90 +32,28 @@
 #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 LDEXP ldexpl
+#define MIN_EXP LDBL_MIN_EXP
+#define MAX_EXP LDBL_MAX_EXP
+#include "test-ldexp.h"
+
 int
 main ()
 {
-  int i;
-  long double x;
-  long double y;
   DECL_LONG_DOUBLE_ROUNDING
 
   BEGIN_LONG_DOUBLE_ROUNDING ();
 
-  { /* NaN.  */
-    x = NaNl ();
-    y = ldexpl (x, 0); ASSERT (isnanl (y));
-    y = ldexpl (x, 5); ASSERT (isnanl (y));
-    y = ldexpl (x, -5); ASSERT (isnanl (y));
-  }
-
-  { /* Positive infinity.  */
-    x = Infinityl ();
-    y = ldexpl (x, 0); ASSERT (y == x);
-    y = ldexpl (x, 5); ASSERT (y == x);
-    y = ldexpl (x, -5); ASSERT (y == x);
-  }
-
-  { /* Negative infinity.  */
-    x = - Infinityl ();
-    y = ldexpl (x, 0); ASSERT (y == x);
-    y = ldexpl (x, 5); ASSERT (y == x);
-    y = ldexpl (x, -5); ASSERT (y == x);
-  }
-
-  { /* Positive zero.  */
-    x = 0.0L;
-    y = ldexpl (x, 0); ASSERT (y == x); ASSERT (!signbit (x));
-    y = ldexpl (x, 5); ASSERT (y == x); ASSERT (!signbit (x));
-    y = ldexpl (x, -5); ASSERT (y == x); ASSERT (!signbit (x));
-  }
-
-  { /* Negative zero.  */
-    x = minus_zerol;
-    y = ldexpl (x, 0); ASSERT (y == x); ASSERT (signbit (x));
-    y = ldexpl (x, 5); ASSERT (y == x); ASSERT (signbit (x));
-    y = ldexpl (x, -5); ASSERT (y == x); ASSERT (signbit (x));
-  }
-
-  { /* Positive finite number.  */
-    x = 1.73205L;
-    y = ldexpl (x, 0); ASSERT (y == x);
-    y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
-    y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
-  }
-
-  { /* Negative finite number.  */
-    x = -20.085536923187667742L;
-    y = ldexpl (x, 0); ASSERT (y == x);
-    y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
-    y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
-  }
-
-  for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
-    {
-      y = ldexpl (x, 0); ASSERT (y == x);
-      {
-        volatile long double expected;
-        y = ldexpl (x, 5);
-        expected = x * 32.0L;
-        ASSERT (y == expected);
-      }
-      y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
-    }
-  for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
-    {
-      y = ldexpl (x, 0); ASSERT (y == x);
-      y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
-      if (i - 5 >= LDBL_MIN_EXP)
-        {
-          y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
-        }
-    }
-  for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
-    {
-      y = ldexpl (x, 0); ASSERT (y == x);
-      y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
-    }
+  test_function ();
 
   return 0;
 }