summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-04-09 12:35:18 +0000
committerthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-04-09 12:35:18 +0000
commit3bc2d502f5f0ce96388ba6ad73c947fd2135e6d9 (patch)
treea1b060aaa1e6eea77e7f6e9b9a1a11450db88e0b
parent90778e8457eee5c89a9ccd84d8fb448853a84e52 (diff)
downloadmpc-3bc2d502f5f0ce96388ba6ad73c947fd2135e6d9.tar.gz
Add a generic test function which tests correct rounding (may give
false warnings in some exceptional cases). git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@85 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--Makefile.am3
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/tgeneric.c77
3 files changed, 81 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 63cf235..2273104 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,5 @@
## Makefile.am -- Process this file with automake to produce Makefile.in
SUBDIRS = src tests doc
-include_HEADERS = $(top_srcdir)/src/mpc.h
+include_HEADERS = src/mpc.h
+EXTRA_DIST = tests/tgeneric.c \ No newline at end of file
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dc0f6a6..1ae8a8c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,8 +2,8 @@
LDADD = $(top_builddir)/src/libmpc.la
-AM_CPPFLAGS = -I$(top_srcdir)/src
-check_PROGRAMS = test tabs tcos tdiv texp tmul tsin tsqr
+AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/tests
+check_PROGRAMS = test tabs tcos tdiv texp tmul tsin tsqr tsqrt
TESTS = $(check_PROGRAMS)
CLEANFILES = mpc_test
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
new file mode 100644
index 0000000..826e663
--- /dev/null
+++ b/tests/tgeneric.c
@@ -0,0 +1,77 @@
+/* file for generic tests.
+
+Copyright (C) 2008 INRIA.
+
+This file is part of the MPC Library.
+
+The MPC Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPC Library 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 Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPC Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpfr.h"
+#include "mpc.h"
+
+#define FUNCTION_NAME(F) #F
+
+static void
+tgeneric()
+{
+ mpc_t x, z, t, u;
+ mp_prec_t prec;
+
+ mpc_init (x);
+ mpc_init (z);
+ mpc_init (t);
+ mpc_init (u);
+
+ for (prec = 2; prec <= 1000; prec++)
+ {
+ mpc_set_prec (x, prec);
+ mpc_set_prec (z, prec);
+ mpc_set_prec (t, prec);
+ mpc_set_prec (u, 4*prec);
+
+ /* We compute the result with four times the precision and check */
+ /* whether the rounding is correct. Error reports in this part of the */
+ /* algorithm might still be wrong, though, since there are two */
+ /* consecutive roundings. */
+ mpc_random (x);
+ TEST_FUNCTION (z, x, MPC_RNDNN);
+ TEST_FUNCTION (u, x, MPC_RNDNN);
+ mpc_set (t, u, MPC_RNDNN);
+
+ if (mpc_cmp (z, t))
+ {
+ fprintf (stderr, "rounding in " FUNCTION_NAME(TEST_FUNCTION) \
+ " might be incorrect for\nx=");
+ mpc_out_str (stderr, 2, 0, x, MPC_RNDNN);
+ fprintf (stderr, "\n" FUNCTION_NAME(TEST_FUNCTION) " "\
+ " gives ");
+ mpc_out_str (stderr, 2, 0, z, MPC_RNDNN);
+ fprintf (stderr, "\n" FUNCTION_NAME(TEST_FUNCTION) " quadruple "\
+ "precision gives ");
+ mpc_out_str (stderr, 2, 0, u, MPC_RNDNN);
+ fprintf (stderr, "\nand is rounded to ");
+ mpc_out_str (stderr, 2, 0, t, MPC_RNDNN);
+ fprintf (stderr, "\n");
+ exit (1);
+ }
+ }
+ mpc_clear (x);
+ mpc_clear (z);
+ mpc_clear (t);
+ mpc_clear (u);
+}