summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-03-05 14:16:38 +0100
committerBruno Haible <bruno@clisp.org>2012-03-05 14:16:38 +0100
commit4dda933b73d7768c4824f13c46fef6fd0e9dfb73 (patch)
tree4a46938399e0623eca8dc9f1465e246aeed55b95
parent0c183c17428707bd6182451e6da6dbb62626e078 (diff)
downloadgnulib-4dda933b73d7768c4824f13c46fef6fd0e9dfb73.tar.gz
cbrt* tests: More tests.
* tests/test-cbrt.h: New file. * tests/test-cbrt.c: Include <float.h> and test-cbrt.h. (main): Invoke test_function. * tests/test-cbrtf.c: Include <float.h> and test-cbrt.h. (main): Invoke test_function. * tests/test-cbrtl.c: Include <float.h> and test-cbrt.h. (main): Invoke test_function. * modules/cbrt-tests (Files): Add tests/test-cbrt.h, tests/randomd.c. (Makefile.am): Add randomd.c to test_cbrt_SOURCES. * modules/cbrtf-tests (Files): Add tests/test-cbrt.h, tests/randomf.c. (Makefile.am): Add randomf.c to test_cbrtf_SOURCES. * modules/cbrtl-tests (Files): Add tests/test-cbrt.h, tests/randoml.c. (Depends-on): Add 'float'. (Makefile.am): Add randoml.c to test_cbrtl_SOURCES.
-rw-r--r--ChangeLog18
-rw-r--r--modules/cbrt-tests3
-rw-r--r--modules/cbrtf-tests3
-rw-r--r--modules/cbrtl-tests4
-rw-r--r--tests/test-cbrt.c12
-rw-r--r--tests/test-cbrt.h59
-rw-r--r--tests/test-cbrtf.c12
-rw-r--r--tests/test-cbrtl.c12
8 files changed, 117 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 09b6051e0b..740e113155 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
2012-03-05 Bruno Haible <bruno@clisp.org>
+ cbrt* tests: More tests.
+ * tests/test-cbrt.h: New file.
+ * tests/test-cbrt.c: Include <float.h> and test-cbrt.h.
+ (main): Invoke test_function.
+ * tests/test-cbrtf.c: Include <float.h> and test-cbrt.h.
+ (main): Invoke test_function.
+ * tests/test-cbrtl.c: Include <float.h> and test-cbrt.h.
+ (main): Invoke test_function.
+ * modules/cbrt-tests (Files): Add tests/test-cbrt.h, tests/randomd.c.
+ (Makefile.am): Add randomd.c to test_cbrt_SOURCES.
+ * modules/cbrtf-tests (Files): Add tests/test-cbrt.h, tests/randomf.c.
+ (Makefile.am): Add randomf.c to test_cbrtf_SOURCES.
+ * modules/cbrtl-tests (Files): Add tests/test-cbrt.h, tests/randoml.c.
+ (Depends-on): Add 'float'.
+ (Makefile.am): Add randoml.c to test_cbrtl_SOURCES.
+
+2012-03-05 Bruno Haible <bruno@clisp.org>
+
hypot* tests: More tests.
* tests/test-hypot.h: New file, partially extracted from
tests/test-hypotl.c.
diff --git a/modules/cbrt-tests b/modules/cbrt-tests
index 47248e056b..9384e2a7cd 100644
--- a/modules/cbrt-tests
+++ b/modules/cbrt-tests
@@ -1,7 +1,9 @@
Files:
tests/test-cbrt.c
+tests/test-cbrt.h
tests/signature.h
tests/macros.h
+tests/randomd.c
Depends-on:
@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-cbrt
check_PROGRAMS += test-cbrt
+test_cbrt_SOURCES = test-cbrt.c randomd.c
test_cbrt_LDADD = $(LDADD) @CBRT_LIBM@
diff --git a/modules/cbrtf-tests b/modules/cbrtf-tests
index 31f328d293..56f32ce371 100644
--- a/modules/cbrtf-tests
+++ b/modules/cbrtf-tests
@@ -1,7 +1,9 @@
Files:
tests/test-cbrtf.c
+tests/test-cbrt.h
tests/signature.h
tests/macros.h
+tests/randomf.c
Depends-on:
@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-cbrtf
check_PROGRAMS += test-cbrtf
+test_cbrtf_SOURCES = test-cbrtf.c randomf.c
test_cbrtf_LDADD = $(LDADD) @CBRTF_LIBM@
diff --git a/modules/cbrtl-tests b/modules/cbrtl-tests
index 1e85c85922..03fce4e506 100644
--- a/modules/cbrtl-tests
+++ b/modules/cbrtl-tests
@@ -1,13 +1,17 @@
Files:
tests/test-cbrtl.c
+tests/test-cbrt.h
tests/signature.h
tests/macros.h
+tests/randoml.c
Depends-on:
+float
configure.ac:
Makefile.am:
TESTS += test-cbrtl
check_PROGRAMS += test-cbrtl
+test_cbrtl_SOURCES = test-cbrtl.c randoml.c
test_cbrtl_LDADD = $(LDADD) @CBRTL_LIBM@
diff --git a/tests/test-cbrt.c b/tests/test-cbrt.c
index e1decb51cb..562c08cd4e 100644
--- a/tests/test-cbrt.c
+++ b/tests/test-cbrt.c
@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (cbrt, 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 CBRT cbrt
+#define RANDOM randomd
+#include "test-cbrt.h"
int
main ()
@@ -36,5 +42,7 @@ main ()
y = cbrt (x);
ASSERT (y >= 0.8434326653 && y <= 0.8434326654);
+ test_function ();
+
return 0;
}
diff --git a/tests/test-cbrt.h b/tests/test-cbrt.h
new file mode 100644
index 0000000000..22403931f4
--- /dev/null
+++ b/tests/test-cbrt.h
@@ -0,0 +1,59 @@
+/* Test of cbrt*() 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. */
+ for (i = 0; i < SIZEOF (RANDOM); i++)
+ {
+ DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
+ DOUBLE y = CBRT (x);
+ DOUBLE err = y * y * y - x;
+ ASSERT (err > - L_(4.0) * L_(16.0) / TWO_MANT_DIG
+ && err < L_(4.0) * L_(16.0) / TWO_MANT_DIG);
+ }
+
+ 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 */
+ if (x != L_(0.0) && y != L_(0.0))
+ {
+ DOUBLE z = L_(1.0) / (x * y);
+ /* Approximately x * y * z = 1. */
+ DOUBLE p = CBRT (x) * CBRT (y) * CBRT (z);
+ ASSERT (p > L_(1.0) - L_(8.0) / TWO_MANT_DIG
+ && p < L_(1.0) + L_(8.0) / TWO_MANT_DIG);
+ }
+ }
+}
+
+volatile DOUBLE x;
+DOUBLE y;
diff --git a/tests/test-cbrtf.c b/tests/test-cbrtf.c
index 53385c754d..08c5b883d9 100644
--- a/tests/test-cbrtf.c
+++ b/tests/test-cbrtf.c
@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (cbrtf, 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 CBRT cbrtf
+#define RANDOM randomf
+#include "test-cbrt.h"
int
main ()
@@ -36,5 +42,7 @@ main ()
y = cbrtf (x);
ASSERT (y >= 0.84343266f && y <= 0.84343270f);
+ test_function ();
+
return 0;
}
diff --git a/tests/test-cbrtl.c b/tests/test-cbrtl.c
index 5f1f0aefb4..79eddf3691 100644
--- a/tests/test-cbrtl.c
+++ b/tests/test-cbrtl.c
@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (cbrtl, long double, (long double));
+#include <float.h>
+
#include "macros.h"
-volatile long double x;
-long double y;
+#define DOUBLE long double
+#define L_(literal) literal##L
+#define MANT_DIG DBL_MANT_DIG
+#define CBRT cbrtl
+#define RANDOM randoml
+#include "test-cbrt.h"
int
main ()
@@ -36,5 +42,7 @@ main ()
y = cbrtl (x);
ASSERT (y >= 0.8434326653L && y <= 0.8434326654L);
+ test_function ();
+
return 0;
}