summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-05-27 13:48:56 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-05-27 13:48:56 +0000
commita8bbca8da73288c230b02e23f8844502e700f844 (patch)
tree121921db74799d1c64ac6832e018fbc6119f7eb8
parent6cc9ba1510baa89ceb8a9590f03c916c9142ade2 (diff)
downloadmpfr-a8bbca8da73288c230b02e23f8844502e700f844.tar.gz
Patch by Kevin Ryde for memory leak checking + misc declaration fixes.
Code moved from mpfr-test.h to tests.c. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1932 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--TODO1
-rw-r--r--const_log2.c4
-rw-r--r--const_pi.c4
-rw-r--r--mpfr-impl.h5
-rw-r--r--mpfr-test.h119
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/memory.c184
-rw-r--r--tests/reuse.c5
-rw-r--r--tests/tabs.c3
-rw-r--r--tests/tacos.c3
-rw-r--r--tests/tacosh.c3
-rw-r--r--tests/tadd.c3
-rw-r--r--tests/tadd_ui.c5
-rw-r--r--tests/tagm.c3
-rw-r--r--tests/tasin.c3
-rw-r--r--tests/tasinh.c3
-rw-r--r--tests/tatan.c3
-rw-r--r--tests/tatanh.c3
-rw-r--r--tests/tcan_round.c4
-rw-r--r--tests/tcmp.c3
-rw-r--r--tests/tcmp2.c2
-rw-r--r--tests/tcmp_ui.c4
-rw-r--r--tests/tconst_euler.c4
-rw-r--r--tests/tconst_log2.c4
-rw-r--r--tests/tconst_pi.c4
-rw-r--r--tests/tcos.c3
-rw-r--r--tests/tcosh.c3
-rw-r--r--tests/tdiv_ui.c6
-rw-r--r--tests/tdump.c4
-rw-r--r--tests/teq.c4
-rw-r--r--tests/tests.c170
-rw-r--r--tests/texceptions.c4
-rw-r--r--tests/texp.c3
-rw-r--r--tests/texp2.c3
-rw-r--r--tests/texpm1.c3
-rw-r--r--tests/tfactorial.c4
-rw-r--r--tests/tfma.c4
-rw-r--r--tests/tget_str.c17
-rw-r--r--tests/thyperbolic.c3
-rw-r--r--tests/thypot.c3
-rw-r--r--tests/tisnan.c4
-rw-r--r--tests/tlog.c8
-rw-r--r--tests/tlog10.c3
-rw-r--r--tests/tlog1p.c3
-rw-r--r--tests/tlog2.c3
-rw-r--r--tests/tmul.c3
-rw-r--r--tests/tmul_2exp.c3
-rw-r--r--tests/tmul_ui.c3
-rw-r--r--tests/tpow.c3
-rw-r--r--tests/tpow3.c4
-rw-r--r--tests/trandom.c4
-rw-r--r--tests/trint.c3
-rw-r--r--tests/tround_prec.c4
-rw-r--r--tests/tset.c4
-rw-r--r--tests/tset_d.c2
-rw-r--r--tests/tset_f.c3
-rw-r--r--tests/tset_q.c5
-rw-r--r--tests/tset_si.c3
-rw-r--r--tests/tset_str.c9
-rw-r--r--tests/tset_z.c3
-rw-r--r--tests/tsin.c3
-rw-r--r--tests/tsinh.c3
-rw-r--r--tests/tsqrt_ui.c5
-rw-r--r--tests/tsub.c3
-rw-r--r--tests/tsub_ui.c6
-rw-r--r--tests/tswap.c4
-rw-r--r--tests/ttan.c3
-rw-r--r--tests/ttanh.c3
-rw-r--r--tests/ttrunc.c4
-rw-r--r--tests/tui_pow.c3
-rw-r--r--tests/tui_sub.c6
71 files changed, 613 insertions, 131 deletions
diff --git a/TODO b/TODO
index 8cbd5e39e..7b4b1a2ed 100644
--- a/TODO
+++ b/TODO
@@ -83,4 +83,3 @@ Miscellaneous:
An advantage of _gmp_rand of course is that it's the same on all
systems, apart from limb size, so you're not at the mercy of random or
lrand48, etc.
-
diff --git a/const_log2.c b/const_log2.c
index 255bc1237..fbeabd44b 100644
--- a/const_log2.c
+++ b/const_log2.c
@@ -27,8 +27,8 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
mpfr_t __mpfr_const_log2; /* stored value of log(2) */
-mp_prec_t __mpfr_const_log2_prec=0; /* precision of stored value */
-mp_rnd_t __mpfr_const_log2_rnd; /* rounding mode of stored value */
+mp_prec_t __mpfr_const_log2_prec = 0; /* precision of stored value */
+static mp_rnd_t __mpfr_const_log2_rnd; /* rounding mode of stored value */
static int mpfr_aux_log2 _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
static int mpfr_const_aux_log2 _PROTO ((mpfr_ptr, mp_rnd_t));
diff --git a/const_pi.c b/const_pi.c
index 1ae1fac43..440594edc 100644
--- a/const_pi.c
+++ b/const_pi.c
@@ -149,8 +149,8 @@ so Pi*16^N-S'(N) <= N+1 (as 1/4/N^2 < 1)
*/
mpfr_t __mpfr_const_pi; /* stored value of Pi */
-int __mpfr_const_pi_prec=0; /* precision of stored value */
-mp_rnd_t __mpfr_const_pi_rnd; /* rounding mode of stored value */
+mp_prec_t __mpfr_const_pi_prec = 0; /* precision of stored value */
+static mp_rnd_t __mpfr_const_pi_rnd; /* rounding mode of stored value */
void
mpfr_const_pi (mpfr_ptr x, mp_rnd_t rnd_mode)
diff --git a/mpfr-impl.h b/mpfr-impl.h
index c91b62b6d..ce2a9fd3d 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -173,7 +173,12 @@ typedef union ieee_double_extract Ieee_double_extract;
extern "C" {
#endif
+extern mpfr_t __mpfr_const_log2;
extern mp_prec_t __mpfr_const_log2_prec;
+
+extern mpfr_t __mpfr_const_pi;
+extern mp_prec_t __mpfr_const_pi_prec;
+
int mpfr_set_underflow _PROTO ((mpfr_ptr, mp_rnd_t, int));
int mpfr_set_overflow _PROTO ((mpfr_ptr, mp_rnd_t, int));
void mpfr_save_emin_emax _PROTO ((void));
diff --git a/mpfr-test.h b/mpfr-test.h
index a4e22d2ec..57245322f 100644
--- a/mpfr-test.h
+++ b/mpfr-test.h
@@ -72,12 +72,6 @@ MA 02111-1307, USA. */
#define random() (mrand48() & 0x7fffffff)
#endif
-void mpfr_test_init _PROTO ((void));
-double drand _PROTO ((void));
-int ulp _PROTO ((double, double));
-double dbl _PROTO ((double, int));
-double Ulp _PROTO ((double));
-
#define MINNORM 2.2250738585072013831e-308 /* 2^(-1022), smallest normalized */
#define MAXNORM 1.7976931348623157081e308 /* 2^(1023)*(2-2^(-52)) */
@@ -92,109 +86,14 @@ double Ulp _PROTO ((double));
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(x) (((x)>0) ? (x) : -(x))
-/* initialization function for tests using the hardware floats */
-void
-mpfr_test_init ()
-{
- double c, d;
- int j;
-#ifdef __mips
- /* to get denormalized numbers on IRIX64 */
- union fpc_csr exp;
+void tests_memory_start _PROTO ((void));
+void tests_memory_end _PROTO ((void));
- exp.fc_word = get_fpc_csr();
- exp.fc_struct.flush = 0;
- set_fpc_csr(exp.fc_word);
-#endif
-#ifdef HAVE_DENORMS
- d = DBL_MIN;
- if (2.0 * (d / 2.0) != d)
- {
- fprintf (stderr, "Warning: no denormalized numbers\n");
- exit (1);
- }
-#endif
+void tests_start_mpfr _PROTO ((void));
+void tests_end_mpfr _PROTO ((void));
-#ifdef HAVE_SETFPUCW
- /* sets the precision to double */
- __setfpucw((_FPU_DEFAULT & (~_FPU_EXTENDED)) | _FPU_DOUBLE);
-#endif
- c = 1.46484375e-3;
- d = 1.0;
- for (j=0; j<54; j++) d *= 0.5;
- d = 0.75 + d;
- d /= 1 << 9;
- if (c != d)
- {
- fprintf (stderr, "Warning: extended precision not disabled\n");
- exit (1);
- }
-}
-
-/* generate a random double using the whole range of possible values,
- including denormalized numbers, NaN, infinities, ... */
-double
-drand (void)
-{
- double d; int *i, expo;
-
- i = (int*) &d;
- d = 1.0;
- if (i[0] == 0)
- expo = 1; /* little endian, exponent in i[1] */
- else
- expo = 0;
- i[0] = LONG_RAND();
- i[1] = LONG_RAND();
- while (i[expo] >= 2146435072)
- i[expo] = LONG_RAND(); /* avoids NaNs */
- if ((LONG_RAND() % 2) && !isnan (d))
- d = -d; /* generates negative numbers */
- return d;
-}
-
-/* returns ulp(x) for x a 'normal' double-precision number */
-double
-Ulp (double x)
-{
- double y, eps;
-
- if (x < 0) x = -x;
-
- y = x * 2.220446049250313080847263336181640625e-16 ; /* x / 2^52 */
-
- /* as ulp(x) <= y = x/2^52 < 2*ulp(x),
- we have x + ulp(x) <= x + y <= x + 2*ulp(x),
- therefore o(x + y) = x + ulp(x) or x + 2*ulp(x) */
-
- eps = x + y;
- eps = eps - x; /* ulp(x) or 2*ulp(x) */
-
- return (eps > y) ? 0.5 * eps : eps;
-}
-
-/* returns the number of ulp's between a and b,
- where a and b can be any floating-point number, except NaN
- */
-int
-ulp (double a, double b)
-{
- double twoa;
-
- if (a == b) return 0; /* also deals with a=b=inf or -inf */
-
- twoa = a + a;
- if (twoa == a) /* a is +/-0.0 or +/-Inf */
- return ((b < a) ? INT_MAX : -INT_MAX);
-
- return (a - b) / Ulp (a);
-}
-
-/* return double m*2^e */
-double
-dbl (double m, int e)
-{
- if (e>=0) while (e-->0) m *= 2.0;
- else while (e++<0) m /= 2.0;
- return m;
-}
+void mpfr_test_init _PROTO ((void));
+double drand _PROTO ((void));
+int ulp _PROTO ((double, double));
+double dbl _PROTO ((double, int));
+double Ulp _PROTO ((double));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e3e65583b..86a33700f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,11 @@
-check_PROGRAMS= reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui tdump teq texp tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos
-EXTRA_DIST= tgeneric.c
+check_PROGRAMS = reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui tdump teq texp tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos
+EXTRA_DIST = tgeneric.c
-LDADD= $(top_builddir)/libmpfr.a @LDADD@
-INCLUDES=-I$(top_srcdir) @INCLUDES@
+LDADD = libfrtests.a $(top_builddir)/libmpfr.a @LDADD@
+INCLUDES = -I$(top_srcdir) @INCLUDES@
+
+check_LIBRARIES = libfrtests.a
+libfrtests_a_SOURCES = memory.c tests.c
../libmpfr.a:
cd $(top_srcdir); make libmpfr.a
diff --git a/tests/memory.c b/tests/memory.c
new file mode 100644
index 000000000..6824b6f0c
--- /dev/null
+++ b/tests/memory.c
@@ -0,0 +1,184 @@
+/* Memory allocation used during tests.
+
+Copyright 2001, 2002 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP 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 GNU MP 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 GNU MP 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> /* for abort */
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "mpfr-test.h"
+
+
+/* Each block allocated is a separate malloc, for the benefit of a redzoning
+ malloc debugger during development or when bug hunting.
+
+ Sizes passed when reallocating or freeing are checked (the default
+ routines don't care about these).
+
+ Memory leaks are checked by requiring that all blocks have been freed
+ when tests_memory_end() is called. Test programs must be sure to have
+ "clear"s for all temporary variables used. */
+
+
+struct header {
+ void *ptr;
+ size_t size;
+ struct header *next;
+};
+
+struct header *tests_memory_list = NULL;
+
+/* Return a pointer to a pointer to the found block (so it can be updated
+ when unlinking). */
+static struct header **
+tests_memory_find (void *ptr)
+{
+ struct header **hp;
+
+ for (hp = &tests_memory_list; *hp != NULL; hp = &((*hp)->next))
+ if ((*hp)->ptr == ptr)
+ return hp;
+
+ return NULL;
+}
+
+static int
+tests_memory_valid (void *ptr)
+{
+ return (tests_memory_find (ptr) != NULL);
+}
+
+static void *
+tests_allocate (size_t size)
+{
+ struct header *h;
+
+ if (size == 0)
+ {
+ printf ("tests_allocate(): attempt to allocate 0 bytes\n");
+ abort ();
+ }
+
+ h = (struct header *) __gmp_default_allocate (sizeof (*h));
+ h->next = tests_memory_list;
+ tests_memory_list = h;
+
+ h->size = size;
+ h->ptr = __gmp_default_allocate (size);
+ return h->ptr;
+}
+
+static void *
+tests_reallocate (void *ptr, size_t old_size, size_t new_size)
+{
+ struct header **hp, *h;
+
+ if (new_size == 0)
+ {
+ printf ("tests_reallocate(): attempt to reallocate 0x%lX to 0 bytes\n",
+ (unsigned long) ptr);
+ abort ();
+ }
+
+ hp = tests_memory_find (ptr);
+ if (hp == NULL)
+ {
+ printf ("tests_reallocate(): attempt to reallocate bad pointer 0x%lX\n",
+ (unsigned long) ptr);
+ abort ();
+ }
+ h = *hp;
+
+ if (h->size != old_size)
+ {
+ printf ("tests_reallocate(): bad old size %u, should be %u\n",
+ old_size, h->size);
+ abort ();
+ }
+
+ h->size = new_size;
+ h->ptr = __gmp_default_reallocate (ptr, old_size, new_size);
+ return h->ptr;
+}
+
+static struct header **
+tests_free_find (void *ptr)
+{
+ struct header **hp = tests_memory_find (ptr);
+ if (hp == NULL)
+ {
+ printf ("tests_free(): attempt to free bad pointer 0x%lX\n",
+ (unsigned long) ptr);
+ abort ();
+ }
+ return hp;
+}
+
+static void
+tests_free_nosize (void *ptr)
+{
+ struct header **hp = tests_free_find (ptr);
+ struct header *h = *hp;
+
+ *hp = h->next; /* unlink */
+
+ __gmp_default_free (ptr, h->size);
+ __gmp_default_free (h, sizeof (*h));
+}
+
+static void
+tests_free (void *ptr, size_t size)
+{
+ struct header **hp = tests_free_find (ptr);
+ struct header *h = *hp;
+
+ if (h->size != size)
+ {
+ printf ("tests_free(): bad size %u, should be %u\n", size, h->size);
+ abort ();
+ }
+
+ tests_free_nosize (ptr);
+}
+
+void
+tests_memory_start (void)
+{
+ mp_set_memory_functions (tests_allocate, tests_reallocate, tests_free);
+}
+
+void
+tests_memory_end (void)
+{
+ if (tests_memory_list != NULL)
+ {
+ struct header *h;
+ unsigned count;
+
+ printf ("tests_memory_end(): not all memory freed\n");
+
+ count = 0;
+ for (h = tests_memory_list; h != NULL; h = h->next)
+ count++;
+
+ printf (" %u blocks remaining\n", count);
+ abort ();
+ }
+}
diff --git a/tests/reuse.c b/tests/reuse.c
index e9ac63970..e9ea078a4 100644
--- a/tests/reuse.c
+++ b/tests/reuse.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
typedef void (*fct_t)();
fct_t testfunc;
@@ -552,6 +553,8 @@ test3a (char *foo, mp_prec_t prec, mp_rnd_t rnd)
int
main (void)
{
+ tests_start_mpfr ();
+
testfunc = (fct_t) mpfr_add; test3 ("mpfr_add", 53, GMP_RNDN);
testfunc = (fct_t) mpfr_add_ui; test2ui ("mpfr_add_ui", 53, GMP_RNDN);
testfunc = (fct_t) mpfr_agm; test3 ("mpfr_agm", 53, GMP_RNDN);
@@ -591,5 +594,7 @@ main (void)
testfunc = (fct_t) mpfr_log2; test2 ("mpfr_log2", 53, GMP_RNDN);
testfunc = (fct_t) mpfr_pow; test3 ("mpfr_pow", 53, GMP_RNDN);
testfunc = (fct_t) mpfr_fma; test4 ("mpfr_fma", 53, GMP_RNDN);
+
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tabs.c b/tests/tabs.c
index 03e566925..a767cda1f 100644
--- a/tests/tabs.c
+++ b/tests/tabs.c
@@ -37,6 +37,8 @@ check_inexact (void)
mp_rnd_t rnd;
int inexact, cmp;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (absx);
@@ -149,5 +151,6 @@ main (int argc, char *argv[])
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tacos.c b/tests/tacos.c
index bfdb52c79..cda4ebf7a 100644
--- a/tests/tacos.c
+++ b/tests/tacos.c
@@ -34,6 +34,8 @@ main (void)
mp_rnd_t rnd;
mpfr_t x, y, z;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -92,5 +94,6 @@ main (void)
mpfr_clear (y);
mpfr_clear (z);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tacosh.c b/tests/tacosh.c
index eddf0f0ec..35ec74b8f 100644
--- a/tests/tacosh.c
+++ b/tests/tacosh.c
@@ -33,8 +33,11 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 25);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tadd.c b/tests/tadd.c
index af0df4e65..8b03e25b5 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -661,6 +661,8 @@ main (int argc, char *argv[])
double x;
int i;
+ tests_start_mpfr ();
+
mpfr_test_init ();
check_inexact ();
check_case_1b ();
@@ -916,5 +918,6 @@ main (int argc, char *argv[])
}
#endif
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c
index a8f330845..befe38e49 100644
--- a/tests/tadd_ui.c
+++ b/tests/tadd_ui.c
@@ -78,7 +78,10 @@ special (void)
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
double x; unsigned long y, N; int i,rnd_mode,rnd;
mpfr_test_init ();
@@ -95,6 +98,7 @@ main (int argc, char *argv[])
check(x, y, rnd);
}
}
+ }
#endif
special ();
check3 (-1.716113812768534e-140, 1271212614, GMP_RNDZ,
@@ -110,6 +114,7 @@ main (int argc, char *argv[])
check3 (DBL_NAN, 2394875, GMP_RNDN, DBL_NAN);
#endif
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tagm.c b/tests/tagm.c
index 830c98f8e..0355ff4a9 100644
--- a/tests/tagm.c
+++ b/tests/tagm.c
@@ -151,6 +151,8 @@ main (int argc, char* argv[])
SEED_RAND (time(NULL));
+ tests_start_mpfr ();
+
if (argc==3) { /* tagm N p : N calculus with precision p*/
printf("Doing %d random tests in %d precision\n",atoi(argv[1]),atoi(argv[2]));
slave(atoi(argv[1]),atoi(argv[2]));
@@ -184,5 +186,6 @@ main (int argc, char* argv[])
/* TODO : tests des infinis dans tagm.c */
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tasin.c b/tests/tasin.c
index ec6119331..778c45f2c 100644
--- a/tests/tasin.c
+++ b/tests/tasin.c
@@ -33,6 +33,8 @@ main (void)
mp_rnd_t rnd;
mpfr_t x, y, z;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -88,5 +90,6 @@ main (void)
mpfr_clear (y);
mpfr_clear (z);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tasinh.c b/tests/tasinh.c
index 61f53236c..0603e3ade 100644
--- a/tests/tasinh.c
+++ b/tests/tasinh.c
@@ -34,6 +34,8 @@ main (int argc, char *argv[])
{
mpfr_t x, y;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
@@ -47,5 +49,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tatan.c b/tests/tatan.c
index 4abd797b7..f2a6101ad 100644
--- a/tests/tatan.c
+++ b/tests/tatan.c
@@ -66,6 +66,8 @@ main (int argc, char *argv[])
mp_rnd_t rnd;
mpfr_t x, y, z, t;
+ tests_start_mpfr ();
+
worst_cases ();
mpfr_init (x);
@@ -124,5 +126,6 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (t);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tatanh.c b/tests/tatanh.c
index e8221ec6c..3b7774623 100644
--- a/tests/tatanh.c
+++ b/tests/tatanh.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 25);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcan_round.c b/tests/tcan_round.c
index 4d5f7e332..a6b614f0d 100644
--- a/tests/tcan_round.c
+++ b/tests/tcan_round.c
@@ -23,12 +23,15 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t x;
+ tests_start_mpfr ();
+
/* checks that rounds to nearest sets the last
bit to zero in case of equal distance */
mpfr_init2 (x, 59);
@@ -56,5 +59,6 @@ main (void)
mpfr_clear (x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcmp.c b/tests/tcmp.c
index 3db356ae4..e60fe18ad 100644
--- a/tests/tcmp.c
+++ b/tests/tcmp.c
@@ -35,6 +35,8 @@ main (void)
int i, c;
mp_prec_t p;
+ tests_start_mpfr ();
+
mpfr_init (xx);
mpfr_init (yy);
@@ -174,5 +176,6 @@ main (void)
mpfr_clear(xx); mpfr_clear(yy);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcmp2.c b/tests/tcmp2.c
index 2b82f92bd..d36350ef1 100644
--- a/tests/tcmp2.c
+++ b/tests/tcmp2.c
@@ -281,6 +281,7 @@ main (void)
{
int i,j; double x=1.0, y, z;
+ tests_start_mpfr ();
mpfr_test_init ();
worst_cases ();
@@ -303,5 +304,6 @@ main (void)
if (y != 0.0 && y != -0.0) tcmp2(x, y, -1);
}
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcmp_ui.c b/tests/tcmp_ui.c
index 76f4831b2..5b6b35a2c 100644
--- a/tests/tcmp_ui.c
+++ b/tests/tcmp_ui.c
@@ -24,12 +24,15 @@ MA 02111-1307, USA. */
#include <math.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t x; unsigned long i; long s;
+ tests_start_mpfr ();
+
mpfr_init(x);
mpfr_set_ui(x, 3, GMP_RNDZ);
@@ -83,5 +86,6 @@ main (void)
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tconst_euler.c b/tests/tconst_euler.c
index 364051ac4..a86b1154d 100644
--- a/tests/tconst_euler.c
+++ b/tests/tconst_euler.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
int
main (int argc, char *argv[])
@@ -32,6 +33,8 @@ main (int argc, char *argv[])
unsigned int err, prec, yprec, p0 = 2, p1 = 200;
mp_rnd_t rnd;
+ tests_start_mpfr ();
+
prec = (argc < 2) ? 53 : atoi(argv[1]);
if (argc > 1)
@@ -86,5 +89,6 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (t);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c
index 4ae036c7d..04817d691 100644
--- a/tests/tconst_log2.c
+++ b/tests/tconst_log2.c
@@ -25,6 +25,7 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
/* tlog2 [prec] [rnd] [0 = no print] */
@@ -77,6 +78,8 @@ main (int argc, char *argv[])
int p;
mp_rnd_t rnd;
+ tests_start_mpfr ();
+
p = (argc>1) ? atoi(argv[1]) : 53;
rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ;
@@ -113,5 +116,6 @@ main (int argc, char *argv[])
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tconst_pi.c b/tests/tconst_pi.c
index 7d26f2da1..fdf6f6d09 100644
--- a/tests/tconst_pi.c
+++ b/tests/tconst_pi.c
@@ -23,6 +23,7 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
/* tpi [prec] [rnd] [0 = no print] */
@@ -31,6 +32,8 @@ main (int argc, char *argv[])
{
mpfr_t x; int p; unsigned char rnd;
+ tests_start_mpfr ();
+
p = (argc>1) ? atoi(argv[1]) : 53;
rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ;
mpfr_init2(x, p);
@@ -43,5 +46,6 @@ main (int argc, char *argv[])
}
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcos.c b/tests/tcos.c
index c87486fe9..aacfa0142 100644
--- a/tests/tcos.c
+++ b/tests/tcos.c
@@ -58,6 +58,8 @@ main (int argc, char *argv[])
{
mpfr_t x, y;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
@@ -127,5 +129,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tcosh.c b/tests/tcosh.c
index 40b2d0ca2..bd431af8a 100644
--- a/tests/tcosh.c
+++ b/tests/tcosh.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c
index 01e063900..6e35c2f9c 100644
--- a/tests/tdiv_ui.c
+++ b/tests/tdiv_ui.c
@@ -175,7 +175,11 @@ int
main (int argc, char **argv)
{
mpfr_t x;
+
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
int i;
unsigned long u;
double d;
@@ -189,6 +193,7 @@ main (int argc, char **argv)
do { d = drand(); } while (ABS(d/u)<DBL_MIN);
check (d, u, LONG_RAND() % 4, 0.0);
}
+ }
#endif
check_inexact ();
@@ -212,5 +217,6 @@ main (int argc, char **argv)
}
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tdump.c b/tests/tdump.c
index fbd1efc0c..9ab6d6372 100644
--- a/tests/tdump.c
+++ b/tests/tdump.c
@@ -23,17 +23,21 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t z;
+ tests_start_mpfr ();
+
mpfr_init2 (z, 2);
mpfr_set_ui (z, 0, GMP_RNDN);
mpfr_dump (z, GMP_RNDD);
printf (" ^--- 0.00e0 printed above is ok\n");
mpfr_clear (z);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/teq.c b/tests/teq.c
index 834972b05..fa2c2857e 100644
--- a/tests/teq.c
+++ b/tests/teq.c
@@ -25,6 +25,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
void teq _PROTO ((mpfr_t));
@@ -66,6 +67,8 @@ main (void)
{
int j; mpfr_t x;
+ tests_start_mpfr ();
+
mpfr_init2 (x, 1000);
for (j=0;j<1000;j++) {
@@ -74,5 +77,6 @@ main (void)
}
mpfr_clear (x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tests.c b/tests/tests.c
new file mode 100644
index 000000000..270776b87
--- /dev/null
+++ b/tests/tests.c
@@ -0,0 +1,170 @@
+/* Miscellaneous support for test programs.
+
+Copyright 2001, 2002 Free Software Foundation, Inc.
+
+This file is part of the MPFR Library.
+
+The MPFR 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 MPFR 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 MPFR 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 "gmp.h"
+#include "gmp-impl.h"
+#include "mpfr.h"
+#include "mpfr-impl.h"
+#include "mpfr-test.h"
+
+
+void
+tests_start_mpfr (void)
+{
+ tests_memory_start ();
+}
+
+void
+tests_end_mpfr (void)
+{
+ if (__mpfr_const_pi_prec != 0)
+ {
+ mpfr_clear (__mpfr_const_pi);
+ __mpfr_const_pi_prec = 0;
+ }
+
+ if (__mpfr_const_log2_prec != 0)
+ {
+ mpfr_clear (__mpfr_const_log2);
+ __mpfr_const_log2_prec = 0;
+ }
+
+ if (__gmp_rands_initialized)
+ {
+ gmp_randclear (__gmp_rands);
+ __gmp_rands_initialized = 0;
+ }
+
+ tests_memory_end ();
+}
+
+/* initialization function for tests using the hardware floats */
+void
+mpfr_test_init ()
+{
+ double c, d;
+ int j;
+#ifdef __mips
+ /* to get denormalized numbers on IRIX64 */
+ union fpc_csr exp;
+
+ exp.fc_word = get_fpc_csr();
+ exp.fc_struct.flush = 0;
+ set_fpc_csr(exp.fc_word);
+#endif
+#ifdef HAVE_DENORMS
+ d = DBL_MIN;
+ if (2.0 * (d / 2.0) != d)
+ {
+ fprintf (stderr, "Warning: no denormalized numbers\n");
+ exit (1);
+ }
+#endif
+
+#ifdef HAVE_SETFPUCW
+ /* sets the precision to double */
+ __setfpucw((_FPU_DEFAULT & (~_FPU_EXTENDED)) | _FPU_DOUBLE);
+#endif
+ c = 1.46484375e-3;
+ d = 1.0;
+ for (j=0; j<54; j++) d *= 0.5;
+ d = 0.75 + d;
+ d /= 1 << 9;
+ if (c != d)
+ {
+ fprintf (stderr, "Warning: extended precision not disabled\n");
+ exit (1);
+ }
+}
+
+/* generate a random double using the whole range of possible values,
+ including denormalized numbers, NaN, infinities, ... */
+double
+drand (void)
+{
+ double d; int *i, expo;
+
+ i = (int*) &d;
+ d = 1.0;
+ if (i[0] == 0)
+ expo = 1; /* little endian, exponent in i[1] */
+ else
+ expo = 0;
+ i[0] = LONG_RAND();
+ i[1] = LONG_RAND();
+ while (i[expo] >= 2146435072)
+ i[expo] = LONG_RAND(); /* avoids NaNs */
+ if ((LONG_RAND() % 2) && !isnan (d))
+ d = -d; /* generates negative numbers */
+ return d;
+}
+
+/* returns ulp(x) for x a 'normal' double-precision number */
+double
+Ulp (double x)
+{
+ double y, eps;
+
+ if (x < 0) x = -x;
+
+ y = x * 2.220446049250313080847263336181640625e-16 ; /* x / 2^52 */
+
+ /* as ulp(x) <= y = x/2^52 < 2*ulp(x),
+ we have x + ulp(x) <= x + y <= x + 2*ulp(x),
+ therefore o(x + y) = x + ulp(x) or x + 2*ulp(x) */
+
+ eps = x + y;
+ eps = eps - x; /* ulp(x) or 2*ulp(x) */
+
+ return (eps > y) ? 0.5 * eps : eps;
+}
+
+/* returns the number of ulp's between a and b,
+ where a and b can be any floating-point number, except NaN
+ */
+int
+ulp (double a, double b)
+{
+ double twoa;
+
+ if (a == b) return 0; /* also deals with a=b=inf or -inf */
+
+ twoa = a + a;
+ if (twoa == a) /* a is +/-0.0 or +/-Inf */
+ return ((b < a) ? INT_MAX : -INT_MAX);
+
+ return (a - b) / Ulp (a);
+}
+
+/* return double m*2^e */
+double
+dbl (double m, int e)
+{
+ if (e >=0 )
+ while (e-- > 0)
+ m *= 2.0;
+ else
+ while (e++ < 0)
+ m /= 2.0;
+ return m;
+}
diff --git a/tests/texceptions.c b/tests/texceptions.c
index 565954ec8..c1c234e2e 100644
--- a/tests/texceptions.c
+++ b/tests/texceptions.c
@@ -23,6 +23,7 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
void mpfr_set_double_range _PROTO((void));
@@ -53,6 +54,8 @@ main (int argc, char *argv[])
mpfr_t x, y;
mp_exp_t emin, emax;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
@@ -119,5 +122,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/texp.c b/tests/texp.c
index b26c2b549..a39fb475a 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -222,6 +222,8 @@ main (int argc, char *argv[])
#endif
double d;
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
if (argc == 4)
@@ -289,5 +291,6 @@ main (int argc, char *argv[])
if (N) printf("mean error=%1.2e max error=%d\n", (double)s/(double)N,maxe);
#endif
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/texp2.c b/tests/texp2.c
index 10315bf84..fe01821e1 100644
--- a/tests/texp2.c
+++ b/tests/texp2.c
@@ -36,6 +36,8 @@ main (int argc, char *argv[])
{
mpfr_t x, y;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
@@ -80,5 +82,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/texpm1.c b/tests/texpm1.c
index 64a6775e5..c1e1d54fa 100644
--- a/tests/texpm1.c
+++ b/tests/texpm1.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tfactorial.c b/tests/tfactorial.c
index c68eb5ae3..712570a4a 100644
--- a/tests/tfactorial.c
+++ b/tests/tfactorial.c
@@ -26,6 +26,7 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
#define TEST_FUNCTION mpfr_fac_ui
@@ -37,6 +38,8 @@ main (int argc, char *argv[])
mpfr_t x, y, z, t;
int inexact;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -114,5 +117,6 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (t);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tfma.c b/tests/tfma.c
index d76f539ca..4bbad6a35 100644
--- a/tests/tfma.c
+++ b/tests/tfma.c
@@ -34,6 +34,9 @@ int
main (int argc, char *argv[])
{
mpfr_t x, y,z,s;
+
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (s);
mpfr_init (y);
@@ -327,5 +330,6 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (s);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tget_str.c b/tests/tget_str.c
index c0852741b..ed5acd68e 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -26,9 +26,7 @@ MA 02111-1307, USA. */
#include <time.h>
#include "gmp.h"
#include "mpfr.h"
-#ifdef MPFR_HAVE_FESETROUND
#include "mpfr-test.h"
-#endif
void check _PROTO((double, mp_rnd_t));
void check3 _PROTO((double, mp_rnd_t, char *));
@@ -43,7 +41,7 @@ check (double d, mp_rnd_t rnd)
mpfr_set_d(x, d, rnd);
str = mpfr_get_str(NULL, &e, 10, 5, x, rnd);
mpfr_clear(x);
- free(str);
+ (*__gmp_free_func) (str, strlen (str) + 1);
}
void
@@ -60,7 +58,7 @@ check3 (double d, mp_rnd_t rnd, char *res)
fprintf (stderr, "got %s instead of %s\n", str, res);
}
mpfr_clear (x);
- free (str);
+ (*__gmp_free_func) (str, strlen (str) + 1);
}
void
@@ -76,7 +74,7 @@ check_small (void)
mpfr_set_prec(x, 63);
mpfr_set_d(x, 5e14, GMP_RNDN);
s = mpfr_get_str(NULL, &e, 10, 18, x, GMP_RNDU);
- free(s);
+ (*__gmp_free_func) (s, strlen (s) + 1);
/* bug found by Johan Vervloet */
mpfr_set_prec(x, 6);
@@ -87,7 +85,7 @@ check_small (void)
mpfr_out_str(stderr, 2, 4, x, GMP_RNDU); putchar('\n');
exit(1);
}
- free(s);
+ (*__gmp_free_func) (s, strlen (s) + 1);
mpfr_set_prec (x, 38);
mpfr_set_str_raw (x, "1.0001110111110100011010100010010100110e-6");
@@ -97,7 +95,7 @@ check_small (void)
fprintf (stderr, "Error in mpfr_get_str (3): s=%s e=%d\n", s, (int) e);
exit (1);
}
- free (s);
+ (*__gmp_free_func) (s, strlen (s) + 1);
mpfr_clear(x);
}
@@ -105,7 +103,10 @@ check_small (void)
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
int i;
double d;
@@ -114,6 +115,7 @@ main (int argc, char *argv[])
do { d = drand(); } while (isnan(d));
check(d, GMP_RNDN);
}
+ }
#endif
check_small();
check3(4.059650008e-83, GMP_RNDN, "40597");
@@ -125,5 +127,6 @@ main (int argc, char *argv[])
check3(7.02293374921793516813e-84, GMP_RNDN, "70229");
check3(-6.7274500420134077e-87, GMP_RNDN, "-67275");
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/thyperbolic.c b/tests/thyperbolic.c
index 3a0f4eba5..c827750db 100644
--- a/tests/thyperbolic.c
+++ b/tests/thyperbolic.c
@@ -23,6 +23,7 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
int check_O _PROTO((void));
@@ -596,11 +597,13 @@ check_O (void)
int
main(void)
{
+tests_start_mpfr ();
if (check_INF())printf("Error in evaluation of INF\n");
if (check_NAN())printf("Error in evaluation of NAN\n");
/*if (check_O())printf("Error in evaluation of composition hyperbolic function\n");*/
+tests_end_mpfr ();
return(0);
diff --git a/tests/thypot.c b/tests/thypot.c
index 3ed8c8610..1b908f82f 100644
--- a/tests/thypot.c
+++ b/tests/thypot.c
@@ -39,6 +39,8 @@ main (int argc, char *argv[])
mpfr_t x1, x2, y, z, t;
int inexact, compare, compare2;
+ tests_start_mpfr ();
+
mpfr_init (x1);
mpfr_init (x2);
mpfr_init (y);
@@ -124,6 +126,7 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (t);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tisnan.c b/tests/tisnan.c
index 45478e9bd..bed502153 100644
--- a/tests/tisnan.c
+++ b/tests/tisnan.c
@@ -23,12 +23,15 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t x;
+ tests_start_mpfr ();
+
mpfr_init (x);
/* check +infinity gives non-zero for mpfr_inf_p only */
@@ -94,5 +97,6 @@ main (void)
mpfr_clear (x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tlog.c b/tests/tlog.c
index efed820ca..b376385c7 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -272,16 +272,18 @@ main (int argc, char *argv[])
int N = 0;
double d;
+ tests_start_mpfr ();
+
SEED_RAND (time(NULL));
if (argc==4) { /* tlog x prec rnd */
check3(atof(argv[1]), atoi(argv[2]), atoi(argv[3]));
- return 0;
+ goto done;
}
if (argc==3) { /* tlog N p : N calculus with precision p*/
printf("Doing %d random tests in %d precision\n",atoi(argv[1]),atoi(argv[2]));
slave(atoi(argv[1]),atoi(argv[2]));
- return 0;
+ goto done;
}
if (argc==2) { /* tlog N: N tests with random double's */
@@ -359,5 +361,7 @@ main (int argc, char *argv[])
test_generic (2, 100, 40);
+ done:
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tlog10.c b/tests/tlog10.c
index 48874218e..b587b68c3 100644
--- a/tests/tlog10.c
+++ b/tests/tlog10.c
@@ -35,6 +35,8 @@ main (int argc, char *argv[])
mpfr_t x, y;
unsigned int n;
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
/* check log10(10^n)=n */
@@ -56,5 +58,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tlog1p.c b/tests/tlog1p.c
index ed9b9645b..5f63b5834 100644
--- a/tests/tlog1p.c
+++ b/tests/tlog1p.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tlog2.c b/tests/tlog2.c
index b5f0878d4..77138586d 100644
--- a/tests/tlog2.c
+++ b/tests/tlog2.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 30);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tmul.c b/tests/tmul.c
index cf51470a1..83e898013 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -356,6 +356,8 @@ main (int argc, char *argv[])
mpfr_test_init ();
#endif
+ tests_start_mpfr ();
+
check_exact ();
check_float ();
#ifdef HAVE_INFS
@@ -405,5 +407,6 @@ main (int argc, char *argv[])
}
#endif
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c
index ce3b4fcb3..9b1827bc6 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2exp.c
@@ -35,6 +35,8 @@ main (int argc, char *argv[])
{
double x, z; mpfr_t w; unsigned long k;
+ tests_start_mpfr ();
+
mpfr_init2(w, 53);
mpfr_set_inf (w, 1);
@@ -68,5 +70,6 @@ main (int argc, char *argv[])
mpfr_clear(w);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c
index 7430c05b7..54533d179 100644
--- a/tests/tmul_ui.c
+++ b/tests/tmul_ui.c
@@ -86,6 +86,8 @@ main (int argc, char *argv[])
unsigned int xprec, yprec, i;
mp_prec_t p;
+ tests_start_mpfr ();
+
for (p=2; p<100; p++)
for (i=1; i<50; i++)
check_inexact (p);
@@ -240,5 +242,6 @@ main (int argc, char *argv[])
mpfr_clear(x); mpfr_clear(y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tpow.c b/tests/tpow.c
index 62d480f60..0780d1883 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -137,11 +137,14 @@ main (void)
{
mp_prec_t p;
+ tests_start_mpfr ();
+
check_pow_ui ();
for (p=2; p<100; p++)
check_inexact (p);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tpow3.c b/tests/tpow3.c
index 5d0c29364..50a1e18ff 100644
--- a/tests/tpow3.c
+++ b/tests/tpow3.c
@@ -35,6 +35,9 @@ main (int argc, char *argv[])
{
mpfr_t x, y, z, ax;
long int iy;
+
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (ax);
mpfr_init2 (y,sizeof(unsigned long int)*CHAR_BIT);
@@ -420,5 +423,6 @@ main (int argc, char *argv[])
mpfr_clear (z);
mpfr_clear (ax);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/trandom.c b/tests/trandom.c
index 70e30a4f2..553ae9cdd 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -26,6 +26,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
void test_random _PROTO ((unsigned long, unsigned long, int));
void test_random2 _PROTO ((unsigned long, unsigned long, int));
@@ -173,6 +174,8 @@ main (int argc, char *argv[])
{
unsigned long nbtests, prec; int verbose = 0;
+ tests_start_mpfr ();
+
if (argc > 1) verbose = 1;
if (argc == 1) { nbtests = 10000; } else nbtests = atoi(argv[1]);
@@ -182,5 +185,6 @@ main (int argc, char *argv[])
test_random2(nbtests, prec, verbose);
test_urandomb(nbtests, prec, verbose);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/trint.c b/tests/trint.c
index e454c5cd3..0f07b22b9 100644
--- a/tests/trint.c
+++ b/tests/trint.c
@@ -35,6 +35,8 @@ main (void)
mp_rnd_t r;
int inexact, sign_t;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
mpz_init (z);
@@ -89,5 +91,6 @@ main (void)
mpz_clear (z);
mpfr_clear (t);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tround_prec.c b/tests/tround_prec.c
index 67334f64e..9d15abdec 100644
--- a/tests/tround_prec.c
+++ b/tests/tround_prec.c
@@ -23,12 +23,15 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t x;
+ tests_start_mpfr ();
+
mpfr_init2 (x, 3);
mpfr_set_ui (x, 5, GMP_RNDN);
@@ -75,5 +78,6 @@ main (void)
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset.c b/tests/tset.c
index 12adeada3..910185050 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -34,6 +34,8 @@ main (void)
mp_rnd_t rnd;
int inexact, cmp;
+ tests_start_mpfr ();
+
/* check prototypes of mpfr_init_set_* */
inexact = mpfr_init_set_si (x, -1, GMP_RNDN);
inexact = mpfr_init_set (y, x, GMP_RNDN);
@@ -79,5 +81,7 @@ main (void)
mpfr_clear (y);
mpfr_clear (z);
mpfr_clear (u);
+
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_d.c b/tests/tset_d.c
index 3b93cc068..5fab50807 100644
--- a/tests/tset_d.c
+++ b/tests/tset_d.c
@@ -34,6 +34,7 @@ main (int argc, char *argv[])
unsigned long k, n;
double d, dd;
+ tests_start_mpfr ();
mpfr_test_init ();
mpfr_init2 (x, 2);
@@ -128,5 +129,6 @@ main (int argc, char *argv[])
mpfr_clear(x); mpfr_clear(y); mpfr_clear(z);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_f.c b/tests/tset_f.c
index e6c5f2287..7506398cb 100644
--- a/tests/tset_f.c
+++ b/tests/tset_f.c
@@ -33,6 +33,8 @@ main (void)
mpf_t y, z;
unsigned long k, pr;
+ tests_start_mpfr ();
+
mpf_init(y);
mpf_init(z);
@@ -81,5 +83,6 @@ main (void)
mpf_clear (y);
mpf_clear (z);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_q.c b/tests/tset_q.c
index bb9ffc37e..8a1f2e066 100644
--- a/tests/tset_q.c
+++ b/tests/tset_q.c
@@ -80,7 +80,10 @@ check (long int n, long int d, mp_rnd_t rnd, double y)
int
main (void)
{
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
long int i, n;
unsigned long int d;
double y;
@@ -97,6 +100,7 @@ main (void)
y = (double) n / d;
check(n, d, rnd, y);
}
+ }
#endif
check(-1647229822, 40619231, GMP_RNDZ, -4.055295438754120596e1);
check(-148939696, 1673285490, GMP_RNDZ, -8.9010331404953485501e-2);
@@ -107,5 +111,6 @@ main (void)
check(643562308, 23100894, GMP_RNDD, 2.7858762002890447462e1);
check(632549085, 1831935802, GMP_RNDN, 3.4528998467600230393e-1);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_si.c b/tests/tset_si.c
index ebe0e72b0..8a0c62a7a 100644
--- a/tests/tset_si.c
+++ b/tests/tset_si.c
@@ -35,6 +35,8 @@ main (int argc, char *argv[])
unsigned long zl, dl, N;
int inex;
+ tests_start_mpfr ();
+
mpfr_init2(x, 100);
SEED_RAND (time(NULL));
@@ -159,5 +161,6 @@ main (int argc, char *argv[])
mpfr_clear(x);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_str.c b/tests/tset_str.c
index ec0546a0a..669d518ef 100644
--- a/tests/tset_str.c
+++ b/tests/tset_str.c
@@ -37,6 +37,8 @@ main (int argc, char *argv[])
mp_exp_t e;
int base, logbase, prec, baseprec;
+ tests_start_mpfr ();
+
if (argc>=2) /* tset_str <string> <prec> */
{
prec = (argc>=3) ? atoi(argv[2]) : 53;
@@ -56,7 +58,7 @@ main (int argc, char *argv[])
bd = LONG_RAND() & 8;
- str2 = str = (char *) malloc (nc * sizeof(char));
+ str2 = str = (*__gmp_allocate_func) (nc * sizeof(char));
if (bd)
{
@@ -93,7 +95,7 @@ main (int argc, char *argv[])
exit(1);
}
- free(str);
+ (*__gmp_free_func) (str, nc * sizeof(char));
mpfr_set_prec (x, 53);
mpfr_set_str_raw (x, "+110101100.01010000101101000000100111001000101011101110E00");
@@ -160,7 +162,7 @@ main (int argc, char *argv[])
mpfr_clear (y);
exit (1);
}
- free (str);
+ (*__gmp_free_func) (str, strlen (str) + 1);
}
if (mpfr_set_str (x, "NaNgarbage", 10, GMP_RNDN) != 3 || !mpfr_nan_p(x))
@@ -193,5 +195,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_z.c b/tests/tset_z.c
index 720302f80..f67a8ee45 100644
--- a/tests/tset_z.c
+++ b/tests/tset_z.c
@@ -66,11 +66,14 @@ main (int argc, char *argv[])
{
long j;
+ tests_start_mpfr ();
+
check_large();
SEED_RAND (time(NULL));
check(0, 0);
for (j=0; j<1000000; j++)
check(LONG_RAND(), LONG_RAND()%4);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsin.c b/tests/tsin.c
index a12b98779..d0df6b9c8 100644
--- a/tests/tsin.c
+++ b/tests/tsin.c
@@ -58,6 +58,8 @@ main (int argc, char *argv[])
{
mpfr_t x;
+ tests_start_mpfr ();
+
#ifdef HAVE_INFS
check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
@@ -100,5 +102,6 @@ main (int argc, char *argv[])
test_generic (2, 100, 80);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsinh.c b/tests/tsinh.c
index 4dfa2db60..5aae5d645 100644
--- a/tests/tsinh.c
+++ b/tests/tsinh.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsqrt_ui.c b/tests/tsqrt_ui.c
index 8f1583786..1f84e5f52 100644
--- a/tests/tsqrt_ui.c
+++ b/tests/tsqrt_ui.c
@@ -59,7 +59,10 @@ check (unsigned long a, mp_rnd_t rnd_mode, double Q)
int
main (void)
{
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
int i;
unsigned long a;
@@ -73,9 +76,11 @@ main (void)
if (1.0*a < 9007199254872064.0)
check(a, LONG_RAND() % 4, -1.0);
}
+ }
#endif
check (0, GMP_RNDN, 0.0);
check (2116118, GMP_RNDU, 1.45468828276026215e3);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsub.c b/tests/tsub.c
index cbf6876da..d2f922200 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -403,6 +403,8 @@ main(void)
mp_prec_t p;
unsigned i;
+ tests_start_mpfr ();
+
check_diverse ();
check_inexact ();
bug_ddefour ();
@@ -411,5 +413,6 @@ main(void)
for (i=0; i<200; i++)
check_two_sum (p);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c
index 538b6fde6..52fab350c 100644
--- a/tests/tsub_ui.c
+++ b/tests/tsub_ui.c
@@ -115,7 +115,11 @@ main (int argc, char *argv[])
{
mp_prec_t p;
int k;
+
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
double x; unsigned long y, N; int i,rnd_mode,rnd;
mpfr_test_init ();
@@ -132,6 +136,7 @@ main (int argc, char *argv[])
check(x, y, rnd);
}
}
+ }
#endif
for (p=2; p<200; p++)
@@ -145,6 +150,7 @@ main (int argc, char *argv[])
check3 (DBL_NEG_INF, 1, GMP_RNDN, DBL_NEG_INF);
#endif
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tswap.c b/tests/tswap.c
index 417fe9f8f..80b75e251 100644
--- a/tests/tswap.c
+++ b/tests/tswap.c
@@ -23,12 +23,15 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
{
mpfr_t u, v;
+ tests_start_mpfr ();
+
mpfr_init2 (u, 24);
mpfr_init2 (v, 53);
mpfr_set_ui (u, 16777215, GMP_RNDN); /* 2^24 - 1 */
@@ -42,5 +45,6 @@ main (void)
mpfr_clear (u);
mpfr_clear (v);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/ttan.c b/tests/ttan.c
index ec4b26ebb..f0efd5eb9 100644
--- a/tests/ttan.c
+++ b/tests/ttan.c
@@ -60,6 +60,8 @@ main(int argc, char *argv[])
unsigned int prec[10] = {14, 15, 19, 22, 23, 24, 25, 40, 41, 52};
unsigned int prec2[10] = {4, 5, 6, 19, 70, 95, 100, 106, 107, 108};
+ tests_start_mpfr ();
+
#ifdef HAVE_INFS
check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
@@ -112,5 +114,6 @@ main(int argc, char *argv[])
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/ttanh.c b/tests/ttanh.c
index 67fc80a44..5d3bd173c 100644
--- a/tests/ttanh.c
+++ b/tests/ttanh.c
@@ -32,7 +32,10 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
+ tests_start_mpfr ();
+
test_generic (2, 100, 100);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/ttrunc.c b/tests/ttrunc.c
index e932ba12a..a28828482 100644
--- a/tests/ttrunc.c
+++ b/tests/ttrunc.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
#define SIZEX 100
@@ -32,6 +33,8 @@ main (void)
{
int j, k; mpfr_t x, y, z, t, y2, z2, t2;
+ tests_start_mpfr ();
+
mpfr_init2(x, SIZEX);
mpfr_init2(y, SIZEX);
mpfr_init2(z, SIZEX);
@@ -140,5 +143,6 @@ main (void)
mpfr_clear(t);
mpfr_clear(t2);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tui_pow.c b/tests/tui_pow.c
index 7e39b4f6e..86d998c33 100644
--- a/tests/tui_pow.c
+++ b/tests/tui_pow.c
@@ -35,6 +35,8 @@ main (int argc, char *argv[])
mpfr_t x, y;
unsigned long int n;
+ tests_start_mpfr ();
+
mpfr_init (x);
mpfr_init (y);
@@ -147,5 +149,6 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ tests_end_mpfr ();
return 0;
}
diff --git a/tests/tui_sub.c b/tests/tui_sub.c
index 016acd051..15694f8ac 100644
--- a/tests/tui_sub.c
+++ b/tests/tui_sub.c
@@ -205,7 +205,11 @@ main (int argc, char *argv[])
{
mp_prec_t p;
unsigned k;
+
+ tests_start_mpfr ();
+
#ifdef MPFR_HAVE_FESETROUND
+ {
double x;
unsigned long y, N;
int i, rnd_mode, rnd;
@@ -224,6 +228,7 @@ main (int argc, char *argv[])
check(y, x, rnd, 0.0);
}
}
+ }
#endif
special ();
for (p=2; p<100; p++)
@@ -247,5 +252,6 @@ main (int argc, char *argv[])
check(293607738, -1.9967571564050541e-5, GMP_RNDU, 2.9360773800002003e8);
check(354270183, 2.9469161763489528e3, GMP_RNDN, 3.5426723608382362e8);
+ tests_end_mpfr ();
return 0;
}