diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2008-07-19 14:40:25 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2008-07-19 14:40:25 +0000 |
commit | 768c0579dc530efe0cd8c18fe4c929dafbf5d911 (patch) | |
tree | 5101e82382bbda2bae0761f666ed976592b11f54 /tests | |
parent | 1c91c6a456532bd9ddbc7b2c323198e24e6df350 (diff) | |
download | mpfr-768c0579dc530efe0cd8c18fe4c929dafbf5d911.tar.gz |
Merged changesets 4953, 4955, 4956, 5347 and 5007 from the trunk: code
clean-up that fixes possible problems on particular platforms. Changes:
* [mpfr-gmp.{c,h}] Function mpfr_init_gmp_rand is no longer defined.
It was private (not documented) and used only in the tests.
User code that calls it is broken and may fail as a consequence.
* [tests] Support 16-bit int's such as on TI-92.
* [tests] No longer use non-reentrant functions such as mpz_random.
* [tests] Avoid mpn_random, which leaks memory.
* [tests] Completed a test in tset_f.c.
* [tests] As a consequence, the tests are performed on different data
(even though the default seed is the same).
This will also make backport of patches easier.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/2.3@5414 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mpfr-test.h | 4 | ||||
-rw-r--r-- | tests/reuse.c | 1 | ||||
-rw-r--r-- | tests/tadd.c | 2 | ||||
-rw-r--r-- | tests/tadd_ui.c | 1 | ||||
-rw-r--r-- | tests/tagm.c | 1 | ||||
-rw-r--r-- | tests/tcan_round.c | 7 | ||||
-rw-r--r-- | tests/tcbrt.c | 1 | ||||
-rw-r--r-- | tests/tcmp.c | 3 | ||||
-rw-r--r-- | tests/tdiv.c | 2 | ||||
-rw-r--r-- | tests/tdiv_ui.c | 1 | ||||
-rw-r--r-- | tests/tests.c | 2 | ||||
-rw-r--r-- | tests/tgamma.c | 1 | ||||
-rw-r--r-- | tests/tget_f.c | 2 | ||||
-rw-r--r-- | tests/tmul.c | 1 | ||||
-rw-r--r-- | tests/tmul_ui.c | 1 | ||||
-rw-r--r-- | tests/tout_str.c | 1 | ||||
-rw-r--r-- | tests/tpow.c | 1 | ||||
-rw-r--r-- | tests/tpow_z.c | 5 | ||||
-rw-r--r-- | tests/trandom.c | 11 | ||||
-rw-r--r-- | tests/troot.c | 1 | ||||
-rw-r--r-- | tests/tset_d.c | 1 | ||||
-rw-r--r-- | tests/tset_f.c | 40 | ||||
-rw-r--r-- | tests/tset_ld.c | 1 | ||||
-rw-r--r-- | tests/tset_q.c | 1 | ||||
-rw-r--r-- | tests/tset_si.c | 3 | ||||
-rw-r--r-- | tests/tset_sj.c | 2 | ||||
-rw-r--r-- | tests/tset_str.c | 1 | ||||
-rw-r--r-- | tests/tset_z.c | 1 | ||||
-rw-r--r-- | tests/tsi_op.c | 1 | ||||
-rw-r--r-- | tests/tstrtofr.c | 1 | ||||
-rw-r--r-- | tests/tsub.c | 1 | ||||
-rw-r--r-- | tests/tsub_ui.c | 1 | ||||
-rw-r--r-- | tests/tui_sub.c | 1 |
33 files changed, 47 insertions, 57 deletions
diff --git a/tests/mpfr-test.h b/tests/mpfr-test.h index b7cf82512..9c895564b 100644 --- a/tests/mpfr-test.h +++ b/tests/mpfr-test.h @@ -89,10 +89,6 @@ int mpfr_cmp_str _MPFR_PROTO ((mpfr_srcptr x, const char *, int, mp_rnd_t)); #define mpfr_cmp0(x,y) (MPFR_ASSERTN (!MPFR_IS_NAN (x) && !MPFR_IS_NAN (y)), mpfr_cmp (x,y)) -#ifndef MPFR_TEST_USE_RANDS -# define MPFR_TEST_USE_RANDS() ((void)0) -#endif - #if defined (__cplusplus) } #endif diff --git a/tests/reuse.c b/tests/reuse.c index f369947c9..5d342e8fd 100644 --- a/tests/reuse.c +++ b/tests/reuse.c @@ -520,7 +520,6 @@ main (void) { mp_rnd_t rnd; mp_prec_t p; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); p = (randlimb () % 200)+ MPFR_PREC_MIN; diff --git a/tests/tadd.c b/tests/tadd.c index 1284b7b03..6a1bbf348 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -1076,9 +1076,7 @@ tests (void) int main (int argc, char *argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); - /* mpfr_test_init (); */ usesp = 0; tests (); diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c index dbb00c2ed..84bc0b90e 100644 --- a/tests/tadd_ui.c +++ b/tests/tadd_ui.c @@ -96,7 +96,6 @@ check_nans (void) int main (int argc, char *argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_nans (); diff --git a/tests/tagm.c b/tests/tagm.c index 660c11889..a9be87886 100644 --- a/tests/tagm.c +++ b/tests/tagm.c @@ -195,7 +195,6 @@ check_nans (void) int main (int argc, char* argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_nans (); diff --git a/tests/tcan_round.c b/tests/tcan_round.c index fddc58218..0f2d17ef0 100644 --- a/tests/tcan_round.c +++ b/tests/tcan_round.c @@ -31,14 +31,16 @@ static void check_round_p (void) { mp_limb_t buf[MAX_LIMB_SIZE]; - mp_size_t n; + mp_size_t n, i; mp_prec_t p; mp_exp_t err; int r1, r2; for (n = 2 ; n <= MAX_LIMB_SIZE ; n++) { - mpn_random (buf, n); + /* avoid mpn_random which leaks memory */ + for (i = 0; i < n; i++) + buf[i] = randlimb (); p = (mp_prec_t) randlimb() % ((n-1) * BITS_PER_MP_LIMB) + MPFR_PREC_MIN; err = p + randlimb () % BITS_PER_MP_LIMB; r1 = mpfr_round_p (buf, n, err, p); @@ -61,7 +63,6 @@ main (void) mpfr_t x; mp_prec_t i, j; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); /* checks that rounds to nearest sets the last diff --git a/tests/tcbrt.c b/tests/tcbrt.c index b593904a4..faa12e5c5 100644 --- a/tests/tcbrt.c +++ b/tests/tcbrt.c @@ -155,7 +155,6 @@ main (void) int r; mp_prec_t p; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); special (); diff --git a/tests/tcmp.c b/tests/tcmp.c index 3e2d3920f..adaa0fd66 100644 --- a/tests/tcmp.c +++ b/tests/tcmp.c @@ -30,7 +30,8 @@ main (void) { double x, y; mpfr_t xx, yy; - int i, c; + int c; + long i; mp_prec_t p; tests_start_mpfr (); diff --git a/tests/tdiv.c b/tests/tdiv.c index a12290592..7d8b44817 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include "mpfr-test.h" @@ -874,7 +873,6 @@ test_20070628 (void) int main (int argc, char *argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_inexact (); diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index 7de581067..f6ba84cb6 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -206,7 +206,6 @@ main (int argc, char **argv) { mpfr_t x; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); special (); diff --git a/tests/tests.c b/tests/tests.c index c7fc06c20..9eb2f8128 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -253,6 +253,8 @@ tests_rand_start (void) "(include this in bug reports)\n", seed); } } + else + gmp_randseed_ui (rands, 0x2143FEDC); } static void diff --git a/tests/tgamma.c b/tests/tgamma.c index 80ea8889d..dcd8494b5 100644 --- a/tests/tgamma.c +++ b/tests/tgamma.c @@ -464,7 +464,6 @@ test20071231 (void) int main (int argc, char *argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); special (); diff --git a/tests/tget_f.c b/tests/tget_f.c index e915f157c..7180aa37a 100644 --- a/tests/tget_f.c +++ b/tests/tget_f.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include <limits.h> #include "mpfr-test.h" @@ -100,7 +99,6 @@ main (void) mp_exp_t e; int inex; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); mpfr_init (y); diff --git a/tests/tmul.c b/tests/tmul.c index 901ec20b5..1debafaef 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -658,7 +658,6 @@ mpfr_mulpi (mpfr_t y, mpfr_t x, mp_rnd_t r) int main (int argc, char *argv[]) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_nans (); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index 62e8fc18f..ad86fd621 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -88,7 +88,6 @@ main (int argc, char *argv[]) mp_prec_t p; mp_exp_t emax; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); for (p=2; p<100; p++) diff --git a/tests/tout_str.c b/tests/tout_str.c index 097ff46ae..d0fae62e1 100644 --- a/tests/tout_str.c +++ b/tests/tout_str.c @@ -24,7 +24,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tpow.c b/tests/tpow.c index b56b64339..4d43e2c38 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -1248,7 +1248,6 @@ main (int argc, char **argv) { mp_prec_t p; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); bug20071127 (); diff --git a/tests/tpow_z.c b/tests/tpow_z.c index 97ae86525..29c6b395a 100644 --- a/tests/tpow_z.c +++ b/tests/tpow_z.c @@ -156,7 +156,9 @@ check_integer (mp_prec_t begin, mp_prec_t end, unsigned long max) mpfr_set_prec (y2, p); for (i = 0 ; i < max ; i++) { - mpz_random (z, (i&1) == 0 ? -1 : 1); + mpz_urandomb (z, RANDS, GMP_NUMB_BITS); + if ((i & 1) != 0) + mpz_neg (z, z); mpfr_random (x); mpfr_mul_2ui (x, x, 1, GMP_RNDN); /* 0 <= x < 2 */ rnd = (mp_rnd_t) RND_RAND (); @@ -296,7 +298,6 @@ check_overflow (void) int main (void) { - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_special (); diff --git a/tests/trandom.c b/tests/trandom.c index f024c0ce6..c8f4c7b5e 100644 --- a/tests/trandom.c +++ b/tests/trandom.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include "mpfr-test.h" @@ -179,7 +178,6 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) { mpfr_t x; int *tab, size_tab, k, sh, xn; - gmp_randstate_t state; double d, av = 0, var = 0, chi2 = 0, th; mp_exp_t emin; @@ -195,12 +193,9 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) xn = 1 + (prec - 1) / mp_bits_per_limb; sh = xn * mp_bits_per_limb - prec; - gmp_randinit (state, GMP_RAND_ALG_LC, 128); - gmp_randseed_ui (state, time(NULL)); - for (k = 0; k < nbtests; k++) { - mpfr_urandomb (x, state); + mpfr_urandomb (x, RANDS); /* check that lower bits are zero */ if (MPFR_MANT(x)[0] & MPFR_LIMB_MASK(sh)) { @@ -216,7 +211,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) emin = mpfr_get_emin (); set_emin (1); /* the generated number in [0,1[ is not in the exponent range, except if it is zero */ - k = mpfr_urandomb (x, state); + k = mpfr_urandomb (x, RANDS); if (MPFR_IS_ZERO(x) == 0 && (k == 0 || mpfr_nan_p (x) == 0)) { printf ("Error in mpfr_urandomb, expected NaN, got "); @@ -226,7 +221,6 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) set_emin (emin); mpfr_clear (x); - gmp_randclear (state); if (!verbose) { free(tab); @@ -263,7 +257,6 @@ main (int argc, char *argv[]) mp_prec_t prec; int verbose = 0; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); if (argc > 1) diff --git a/tests/troot.c b/tests/troot.c index aa9baa0e8..a9b52ec56 100644 --- a/tests/troot.c +++ b/tests/troot.c @@ -268,7 +268,6 @@ main (void) mp_prec_t p; unsigned long k; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); special (); diff --git a/tests/tset_d.c b/tests/tset_d.c index 9eeef0416..d9178b15c 100644 --- a/tests/tset_d.c +++ b/tests/tset_d.c @@ -23,7 +23,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <float.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tset_f.c b/tests/tset_f.c index ae7ea63ca..88e22aeda 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include <limits.h> /* for ULONG_MAX */ #include "mpfr-test.h" @@ -36,7 +35,6 @@ main (void) unsigned long k, pr; int r, inexact; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); mpf_init (y); @@ -49,7 +47,7 @@ main (void) mpfr_set_prec (x, 100); mpfr_set_f (x, y, GMP_RNDN); - mpf_random2 (y, 10, 0); + mpf_urandomb (y, RANDS, 10 * GMP_NUMB_BITS); mpfr_set_f (x, y, (mp_rnd_t) RND_RAND()); /* bug found by Jean-Pierre Merlet */ @@ -57,8 +55,8 @@ main (void) mpf_set_prec (y, 256); mpfr_init2 (u, 256); mpfr_set_str (u, - "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2", - 16, GMP_RNDN); + "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2", + 16, GMP_RNDN); mpf_set_str (y, "2033033E-3", 10); /* avoid 2033.033 which is locale-sensitive */ mpfr_set_f (x, y, GMP_RNDN); @@ -90,13 +88,39 @@ main (void) } MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, 901) == 0); - for (k = 1; k <= 100000; k++) + /* random values */ + for (k = 1; k <= 1000; k++) { pr = 2 + (randlimb () & 255); mpf_set_prec (z, pr); - mpf_random2 (z, z->_mp_prec, 0); + mpf_urandomb (z, RANDS, z->_mp_prec); + mpfr_set_prec (u, ((pr / BITS_PER_MP_LIMB + 1) * BITS_PER_MP_LIMB)); + mpfr_set_f (u, z, GMP_RNDN); + if (mpfr_cmp_f (u , z) != 0) + { + printf ("Error in mpfr_set_f:\n"); + printf ("mpf (precision=%lu)=", pr); + mpf_out_str (stdout, 16, 0, z); + printf ("\nmpfr(precision=%lu)=", + ((pr / BITS_PER_MP_LIMB + 1) * BITS_PER_MP_LIMB)); + mpfr_out_str (stdout, 16, 0, u, GMP_RNDN); + putchar ('\n'); + exit (1); + } mpfr_set_prec (x, pr); - mpfr_set_f (x, z, (mp_rnd_t) 0); + mpfr_set_f (x, z, GMP_RNDN); + mpfr_sub (u, u, x, GMP_RNDN); + mpfr_abs (u, u, GMP_RNDN); + if (mpfr_cmp_ui_2exp (u, 1, -pr - 1) > 0) + { + printf ("Error in mpfr_set_f: precision=%lu\n", pr); + printf ("mpf ="); + mpf_out_str (stdout, 16, 0, z); + printf ("\nmpfr="); + mpfr_out_str (stdout, 16, 0, x, GMP_RNDN); + putchar ('\n'); + exit (1); + } } /* Check for +0 */ diff --git a/tests/tset_ld.c b/tests/tset_ld.c index df15b488e..752b18424 100644 --- a/tests/tset_ld.c +++ b/tests/tset_ld.c @@ -23,7 +23,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <float.h> -#include <time.h> #include <limits.h> #if WITH_FPU_CONTROL #include <fpu_control.h> diff --git a/tests/tset_q.c b/tests/tset_q.c index 88162a753..d74f3c15b 100644 --- a/tests/tset_q.c +++ b/tests/tset_q.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tset_si.c b/tests/tset_si.c index 9029bdac3..0a1339739 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -22,7 +22,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include <limits.h> #include "mpfr-test.h" @@ -49,7 +48,7 @@ test_2exp (void) if (mpfr_cmp_ui(x, 1024*1024)) ERROR("(1024U,+10)"); - mpfr_set_si_2exp (x, -1024*1024, -10, GMP_RNDN); + mpfr_set_si_2exp (x, -1024L * 1024L, -10, GMP_RNDN); if (mpfr_cmp_si(x, -1024)) ERROR("(1M,-10)"); diff --git a/tests/tset_sj.c b/tests/tset_sj.c index 4612204e9..b8bb2aeb4 100644 --- a/tests/tset_sj.c +++ b/tests/tset_sj.c @@ -127,7 +127,7 @@ check_set_uj_2exp (void) ERROR("(1024U,-10)"); inex = mpfr_set_uj_2exp (x, 1024, 10, GMP_RNDN); - if (inex || mpfr_cmp_ui(x, 1024*1024)) + if (inex || mpfr_cmp_ui(x, 1024L * 1024L)) ERROR("(1024U,+10)"); inex = mpfr_set_uj_2exp (x, UINTMAX_MAX, 1000, GMP_RNDN); diff --git a/tests/tset_str.c b/tests/tset_str.c index 0a1ea5067..e0e0f80ea 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -24,7 +24,6 @@ MA 02110-1301, USA. */ #include <stdlib.h> #include <string.h> #include <limits.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tset_z.c b/tests/tset_z.c index a3fe7c5a8..962e70b0e 100644 --- a/tests/tset_z.c +++ b/tests/tset_z.c @@ -23,7 +23,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <limits.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tsi_op.c b/tests/tsi_op.c index c95fee921..00136811f 100644 --- a/tests/tsi_op.c +++ b/tests/tsi_op.c @@ -101,7 +101,6 @@ main (int argc, char *argv[]) int y; int i; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); mpfr_inits2 (53, x, z, (void *) 0); for(i = 0 ; i < numberof (tab) ; i++) diff --git a/tests/tstrtofr.c b/tests/tstrtofr.c index f0cf7ade8..3a0862809 100644 --- a/tests/tstrtofr.c +++ b/tests/tstrtofr.c @@ -24,7 +24,6 @@ MA 02110-1301, USA. */ #include <stdlib.h> #include <string.h> #include <limits.h> -#include <time.h> #include "mpfr-test.h" diff --git a/tests/tsub.c b/tests/tsub.c index e7ec5ef1a..cca9b8080 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -482,7 +482,6 @@ main (void) mp_prec_t p; unsigned int i; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_diverse (); diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index b9c9143d6..3dadacbd8 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -126,7 +126,6 @@ main (int argc, char *argv[]) mp_prec_t p; int k; - MPFR_TEST_USE_RANDS (); tests_start_mpfr (); check_nans (); diff --git a/tests/tui_sub.c b/tests/tui_sub.c index 9b3e69e1d..cadd511f9 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -23,7 +23,6 @@ MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <float.h> -#include <time.h> #include "mpfr-test.h" |