summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--modules/sqrt-tests3
-rw-r--r--modules/sqrtf-tests3
-rw-r--r--modules/sqrtl-tests4
-rw-r--r--tests/test-sqrt.c12
-rw-r--r--tests/test-sqrt.h59
-rw-r--r--tests/test-sqrtf.c12
-rw-r--r--tests/test-sqrtl.c12
8 files changed, 118 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 7a01288dd7..4ec700fd59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,22 @@
-2012-03-03 Bruno Haible <bruno@clisp.org>
+2012-03-04 Bruno Haible <bruno@clisp.org>
+
+ sqrt* tests: More tests.
+ * tests/test-sqrt.h: New file.
+ * tests/test-sqrt.c: Include <float.h> and test-sqrt.h.
+ (main): Invoke test_function.
+ * tests/test-sqrtf.c: Include <float.h> and test-sqrt.h.
+ (main): Invoke test_function.
+ * tests/test-sqrtl.c: Include <float.h> and test-sqrt.h.
+ (main): Invoke test_function.
+ * modules/sqrt-tests (Files): Add tests/test-sqrt.h, tests/randomd.c.
+ (Makefile.am): Add randomd.c to test_sqrt_SOURCES.
+ * modules/sqrtf-tests (Files): Add tests/test-sqrt.h, tests/randomf.c.
+ (Makefile.am): Add randomf.c to test_sqrtf_SOURCES.
+ * modules/sqrtl-tests (Files): Add tests/test-sqrt.h, tests/randoml.c.
+ (Depends-on): Add 'float'.
+ (Makefile.am): Add randoml.c to test_sqrtl_SOURCES.
+
+2012-03-04 Bruno Haible <bruno@clisp.org>
remainder* tests: More tests.
* tests/test-remainder.h: New file, based on tests/test-fmod.h.
diff --git a/modules/sqrt-tests b/modules/sqrt-tests
index 86d8176159..dad976d7c9 100644
--- a/modules/sqrt-tests
+++ b/modules/sqrt-tests
@@ -1,7 +1,9 @@
Files:
tests/test-sqrt.c
+tests/test-sqrt.h
tests/signature.h
tests/macros.h
+tests/randomd.c
Depends-on:
@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-sqrt
check_PROGRAMS += test-sqrt
+test_sqrt_SOURCES = test-sqrt.c randomd.c
test_sqrt_LDADD = $(LDADD) @SQRT_LIBM@
diff --git a/modules/sqrtf-tests b/modules/sqrtf-tests
index 3cd8d62c56..7b0525eb82 100644
--- a/modules/sqrtf-tests
+++ b/modules/sqrtf-tests
@@ -1,7 +1,9 @@
Files:
tests/test-sqrtf.c
+tests/test-sqrt.h
tests/signature.h
tests/macros.h
+tests/randomf.c
Depends-on:
@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-sqrtf
check_PROGRAMS += test-sqrtf
+test_sqrtf_SOURCES = test-sqrtf.c randomf.c
test_sqrtf_LDADD = $(LDADD) @SQRTF_LIBM@
diff --git a/modules/sqrtl-tests b/modules/sqrtl-tests
index eab018b718..68c4068f00 100644
--- a/modules/sqrtl-tests
+++ b/modules/sqrtl-tests
@@ -1,14 +1,18 @@
Files:
tests/test-sqrtl.c
+tests/test-sqrt.h
tests/signature.h
tests/macros.h
+tests/randoml.c
Depends-on:
fpucw
+float
configure.ac:
Makefile.am:
TESTS += test-sqrtl
check_PROGRAMS += test-sqrtl
+test_sqrtl_SOURCES = test-sqrtl.c randoml.c
test_sqrtl_LDADD = $(LDADD) @SQRTL_LIBM@
diff --git a/tests/test-sqrt.c b/tests/test-sqrt.c
index 0de7051e69..b317eb7ccf 100644
--- a/tests/test-sqrt.c
+++ b/tests/test-sqrt.c
@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (sqrt, 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 SQRT sqrt
+#define RANDOM randomd
+#include "test-sqrt.h"
int
main ()
@@ -36,5 +42,7 @@ main ()
y = sqrt (x);
ASSERT (y >= 0.7745966692 && y <= 0.7745966693);
+ test_function ();
+
return 0;
}
diff --git a/tests/test-sqrt.h b/tests/test-sqrt.h
new file mode 100644
index 0000000000..ffd5af1a7f
--- /dev/null
+++ b/tests/test-sqrt.h
@@ -0,0 +1,59 @@
+/* Test of sqrt*() 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_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
+ DOUBLE y = SQRT (x);
+ DOUBLE z = y * y - x;
+ ASSERT (z > - L_(16.0) / TWO_MANT_DIG
+ && z < L_(16.0) / TWO_MANT_DIG);
+ }
+
+ for (i = 0; i < SIZEOF (RANDOM) / 4; i++)
+ for (j = 0; j < SIZEOF (RANDOM) / 4; j++)
+ {
+ DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
+ DOUBLE y = L_(16.0) * RANDOM[j]; /* 0.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 = SQRT (x) * SQRT (y) * SQRT (z);
+ ASSERT (p > L_(1.0) - L_(4.0) / TWO_MANT_DIG
+ && p < L_(1.0) + L_(4.0) / TWO_MANT_DIG);
+ }
+ }
+}
+
+volatile DOUBLE x;
+DOUBLE y;
diff --git a/tests/test-sqrtf.c b/tests/test-sqrtf.c
index 514eb7e5f2..40abde6cf5 100644
--- a/tests/test-sqrtf.c
+++ b/tests/test-sqrtf.c
@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (sqrtf, 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 SQRT sqrtf
+#define RANDOM randomf
+#include "test-sqrt.h"
int
main ()
@@ -36,5 +42,7 @@ main ()
y = sqrtf (x);
ASSERT (y >= 0.7745966f && y <= 0.7745967f);
+ test_function ();
+
return 0;
}
diff --git a/tests/test-sqrtl.c b/tests/test-sqrtl.c
index fa2889cb99..23dcfe43ae 100644
--- a/tests/test-sqrtl.c
+++ b/tests/test-sqrtl.c
@@ -23,11 +23,17 @@
#include "signature.h"
SIGNATURE_CHECK (sqrtl, 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 DBL_MANT_DIG
+#define SQRT sqrtl
+#define RANDOM randoml
+#include "test-sqrt.h"
int
main ()
@@ -41,5 +47,7 @@ main ()
y = sqrtl (x);
ASSERT (y >= 0.7745966692L && y <= 0.7745966693L);
+ test_function ();
+
return 0;
}