]> Savannah Git Hosting - gnulib.git/commitdiff
exp* tests: More tests.
authorBruno Haible <bruno@clisp.org>
Tue, 6 Mar 2012 02:05:14 +0000 (03:05 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 6 Mar 2012 02:05:14 +0000 (03:05 +0100)
* tests/test-exp.h: New file.
* tests/test-exp.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expf.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expl.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* modules/exp-tests (Files): Add tests/test-exp.h, tests/randomd.c.
(Makefile.am): Add randomd.c to test_exp_SOURCES.
* modules/expf-tests (Files): Add tests/test-exp.h, tests/randomf.c.
(Makefile.am): Add randomf.c to test_expf_SOURCES.
* modules/expl-tests (Files): Add tests/test-exp.h, tests/randoml.c.
(Depends-on): Add 'float'.
(Makefile.am): Add randoml.c to test_expl_SOURCES.

ChangeLog
modules/exp-tests
modules/expf-tests
modules/expl-tests
tests/test-exp.c
tests/test-exp.h [new file with mode: 0644]
tests/test-expf.c
tests/test-expl.c

index a18d03370293f7356e2368916f66f84c82abdb9c..411846fefca1dc6038129dbd8d65b2a354329139 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2012-03-05  Bruno Haible  <bruno@clisp.org>
 
+       exp* tests: More tests.
+       * tests/test-exp.h: New file.
+       * tests/test-exp.c: Include <float.h> and test-exp.h.
+       (main): Invoke test_function.
+       * tests/test-expf.c: Include <float.h> and test-exp.h.
+       (main): Invoke test_function.
+       * tests/test-expl.c: Include <float.h> and test-exp.h.
+       (main): Invoke test_function.
+       * modules/exp-tests (Files): Add tests/test-exp.h, tests/randomd.c.
+       (Makefile.am): Add randomd.c to test_exp_SOURCES.
+       * modules/expf-tests (Files): Add tests/test-exp.h, tests/randomf.c.
+       (Makefile.am): Add randomf.c to test_expf_SOURCES.
+       * modules/expl-tests (Files): Add tests/test-exp.h, tests/randoml.c.
+       (Depends-on): Add 'float'.
+       (Makefile.am): Add randoml.c to test_expl_SOURCES.
+
        expl: Fix precision of computed result.
        * lib/expl.c: Completely rewritten.
        * modules/expl (Depends-on): Add isnanl, roundl, ldexpl. Remove floorl.
index 133886117eda10927c34253c6a840c6b0fb64715..0b5ad6917c11b0ca71f49e734f46eaa08d5d3929 100644 (file)
@@ -1,7 +1,9 @@
 Files:
 tests/test-exp.c
+tests/test-exp.h
 tests/signature.h
 tests/macros.h
+tests/randomd.c
 
 Depends-on:
 
@@ -10,4 +12,5 @@ configure.ac:
 Makefile.am:
 TESTS += test-exp
 check_PROGRAMS += test-exp
+test_exp_SOURCES = test-exp.c randomd.c
 test_exp_LDADD = $(LDADD) @EXP_LIBM@
index ec6d58238e7e7a9e89c5f60438d704d367378ff0..b1d1c4ac1185a245e461c3b1999b9a9406194282 100644 (file)
@@ -1,7 +1,9 @@
 Files:
 tests/test-expf.c
+tests/test-exp.h
 tests/signature.h
 tests/macros.h
+tests/randomf.c
 
 Depends-on:
 
@@ -10,4 +12,5 @@ configure.ac:
 Makefile.am:
 TESTS += test-expf
 check_PROGRAMS += test-expf
+test_expf_SOURCES = test-expf.c randomf.c
 test_expf_LDADD = $(LDADD) @EXPF_LIBM@
index bc7b28ae35a787b37306c9f44c91370ed02ad357..5296c2b3a938b98e1957dffef6876e92e85c5e3d 100644 (file)
@@ -1,14 +1,18 @@
 Files:
 tests/test-expl.c
+tests/test-exp.h
 tests/signature.h
 tests/macros.h
+tests/randoml.c
 
 Depends-on:
 fpucw
+float
 
 configure.ac:
 
 Makefile.am:
 TESTS += test-expl
 check_PROGRAMS += test-expl
+test_expl_SOURCES = test-expl.c randoml.c
 test_expl_LDADD = $(LDADD) @EXPL_LIBM@
index 8eb0aa52db56e1d5d209fe256cfebe473d8bd053..0459739d1475c5b1f34b6214cd228469ea5853e2 100644 (file)
 #include "signature.h"
 SIGNATURE_CHECK (exp, double, (double));
 
+#include <float.h>
+
 #include "macros.h"
 
-volatile double x;
-double y;
+#define DOUBLE double
+#define L_(literal) literal
+#define MANT_DIG DBL_MANT_DIG
+#define EXP exp
+#define RANDOM randomd
+#include "test-exp.h"
 
 int
 main ()
@@ -36,5 +42,7 @@ main ()
   y = exp (x);
   ASSERT (y >= 1.822118800 && y <= 1.822118801);
 
+  test_function ();
+
   return 0;
 }
diff --git a/tests/test-exp.h b/tests/test-exp.h
new file mode 100644 (file)
index 0000000..c2609b7
--- /dev/null
@@ -0,0 +1,88 @@
+/* Test of exp*() function family.
+   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)
+{
+  int i;
+  int j;
+  const DOUBLE TWO_MANT_DIG =
+    /* Assume MANT_DIG <= 5 * 31.
+       Use the identity
+         n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5).  */
+    (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
+    * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
+    * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
+    * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
+    * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
+
+  /* Randomized tests.  */
+  {
+    /* Error bound, in ulps.  */
+    const DOUBLE err_bound =
+      (sizeof (DOUBLE) == sizeof (long double) ?
+#if defined __i386__ && defined __FreeBSD__
+       /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
+          precision in the compiler but 64 bits of precision at runtime.  See
+          <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>.
+          The compiler has truncated all 'long double' literals in expl.c to
+          53 bits of precision.  */
+       L_(1350.0)
+#else
+       L_(4.0)
+#endif
+       : L_(2.0));
+
+    for (i = 0; i < SIZEOF (RANDOM); i++)
+      {
+        DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
+        DOUBLE y = EXP (x);
+        DOUBLE z = EXP (- x);
+        DOUBLE err = y * z - L_(1.0);
+        ASSERT (y > L_(0.0));
+        ASSERT (z > L_(0.0));
+        ASSERT (err > - err_bound / TWO_MANT_DIG
+                && err < err_bound / TWO_MANT_DIG);
+      }
+  }
+
+  {
+    /* Error bound, in ulps.  */
+    const DOUBLE err_bound =
+      (sizeof (DOUBLE) == sizeof (long double) ?
+#if defined __i386__ && defined __FreeBSD__
+       L_(2400.0)
+#else
+       L_(24.0)
+#endif
+       : L_(24.0));
+
+    for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
+      for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
+        {
+          DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
+          DOUBLE y = L_(32.0) * RANDOM[j] - L_(16.0); /* -16.0 <= y <= 16.0 */
+          DOUBLE z = - x - y;
+          /* Approximately  x + y + z = 0.  */
+          DOUBLE err = EXP (x) * EXP (y) * EXP (z) - L_(1.0);
+          ASSERT (err > - err_bound / TWO_MANT_DIG
+                  && err < err_bound / TWO_MANT_DIG);
+        }
+  }
+}
+
+volatile DOUBLE x;
+DOUBLE y;
index f16026e7867bcf1030d306eb8d21e1a60ec6bc28..d7ae2858e7b749a8d3dfb99d4fc12570206d217f 100644 (file)
 #include "signature.h"
 SIGNATURE_CHECK (expf, float, (float));
 
+#include <float.h>
+
 #include "macros.h"
 
-volatile float x;
-float y;
+#define DOUBLE float
+#define L_(literal) literal##f
+#define MANT_DIG FLT_MANT_DIG
+#define EXP expf
+#define RANDOM randomf
+#include "test-exp.h"
 
 int
 main ()
@@ -36,5 +42,7 @@ main ()
   y = expf (x);
   ASSERT (y >= 1.8221188f && y <= 1.8221189f);
 
+  test_function ();
+
   return 0;
 }
index 21dc65e645a3cf540c4cd6aae09bf97f326995e2..73091065329c6d9e0c0197945b729403b5e88d34 100644 (file)
 #include "signature.h"
 SIGNATURE_CHECK (expl, long double, (long double));
 
+#include <float.h>
+
 #include "fpucw.h"
 #include "macros.h"
 
-volatile long double x;
-long double y;
+#define DOUBLE long double
+#define L_(literal) literal##L
+#define MANT_DIG LDBL_MANT_DIG
+#define EXP expl
+#define RANDOM randoml
+#include "test-exp.h"
 
 int
 main ()
@@ -41,5 +47,7 @@ main ()
   y = expl (x);
   ASSERT (y >= 1.822118800L && y <= 1.822118801L);
 
+  test_function ();
+
   return 0;
 }