diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-06-12 16:13:49 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-06-12 16:13:49 +0000 |
commit | 573b63b71ddcfbc2836ee1f37c6fc0bc3accbd0a (patch) | |
tree | e94044c2aa8d50e582713343cc6dc9a1d35112cc | |
parent | e976dd7979c00f2fc9fc448d151fa74febe3223f (diff) | |
download | mpfr-573b63b71ddcfbc2836ee1f37c6fc0bc3accbd0a.tar.gz |
Replaced misc random functions by GMP ones.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2329 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | acinclude.m4 | 3 | ||||
-rw-r--r-- | mpfr-test.h | 22 | ||||
-rw-r--r-- | tests/tabs.c | 8 | ||||
-rw-r--r-- | tests/tacos.c | 2 | ||||
-rw-r--r-- | tests/tadd.c | 4 | ||||
-rw-r--r-- | tests/tagm.c | 31 | ||||
-rw-r--r-- | tests/tasin.c | 4 | ||||
-rw-r--r-- | tests/tatan.c | 2 | ||||
-rw-r--r-- | tests/tcmp.c | 5 | ||||
-rw-r--r-- | tests/tcmp2.c | 3 | ||||
-rw-r--r-- | tests/tdiv_ui.c | 2 | ||||
-rw-r--r-- | tests/terf.c | 4 | ||||
-rw-r--r-- | tests/tests.c | 33 | ||||
-rw-r--r-- | tests/texp.c | 2 | ||||
-rw-r--r-- | tests/tfma.c | 10 | ||||
-rw-r--r-- | tests/tgamma.c | 2 | ||||
-rw-r--r-- | tests/tgeneric.c | 2 | ||||
-rw-r--r-- | tests/thypot.c | 8 | ||||
-rw-r--r-- | tests/tlog.c | 16 | ||||
-rw-r--r-- | tests/tmul.c | 2 | ||||
-rw-r--r-- | tests/tmul_2exp.c | 5 | ||||
-rw-r--r-- | tests/tmul_ui.c | 2 | ||||
-rw-r--r-- | tests/tout_str.c | 8 | ||||
-rw-r--r-- | tests/tpow.c | 2 | ||||
-rw-r--r-- | tests/tpow3.c | 4 | ||||
-rw-r--r-- | tests/trint.c | 4 | ||||
-rw-r--r-- | tests/tset.c | 2 | ||||
-rw-r--r-- | tests/tset_d.c | 5 | ||||
-rw-r--r-- | tests/tset_f.c | 8 | ||||
-rw-r--r-- | tests/tset_si.c | 9 | ||||
-rw-r--r-- | tests/tset_str.c | 15 | ||||
-rw-r--r-- | tests/tset_z.c | 5 | ||||
-rw-r--r-- | tests/tsqrt.c | 2 | ||||
-rw-r--r-- | tests/tsub.c | 4 | ||||
-rw-r--r-- | tests/tsub_ui.c | 4 | ||||
-rw-r--r-- | tests/tui_div.c | 2 | ||||
-rw-r--r-- | tests/tui_pow.c | 9 | ||||
-rw-r--r-- | tests/tui_sub.c | 4 | ||||
-rw-r--r-- | tests/tzeta.c | 6 |
39 files changed, 127 insertions, 138 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 0ae0b48ef..e5c25ab82 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -128,9 +128,6 @@ if test "$mpfr_cv_have_fesetround" = "yes"; then AC_DEFINE(MPFR_HAVE_FESETROUND,1,[Define if you have the `fesetround' function via the <fenv.h> header file.]) fi -dnl Check random functions -AC_CHECK_FUNCS(lrand48) - dnl Check whether 0/0, 1/0, -1/0, sqrt(-1) are valid expressions AC_CACHE_CHECK([for valid NaN], mpfr_cv_valid_nan, [ AC_TRY_RUN([ diff --git a/mpfr-test.h b/mpfr-test.h index d26b9851d..1553e6160 100644 --- a/mpfr-test.h +++ b/mpfr-test.h @@ -28,27 +28,9 @@ MA 02111-1307, USA. */ #include "config.h" #endif -/* Because of the SunOS 4 compiler */ -#ifndef RAND_MAX -#define RAND_MAX 0x7FFFFFFF -#endif - /* generates a random long int, a random double, and corresponding seed initializing */ -#ifdef HAVE_LRAND48 -#define LONG_RAND lrand48 -#define DBL_RAND drand48 -#define SEED_RAND srand48 -#else -#define LONG_RAND random -#define DBL_RAND() ((double) random() / (double) RAND_MAX) -#define SEED_RAND srandom -#endif - -#if defined (__hpux) -#define srandom srand48 -#define random() (mrand48() & 0x7fffffff) -#endif +#define DBL_RAND() ((double) randlimb() / (double) MP_LIMB_T_MAX) #define MINNORM 2.2250738585072013831e-308 /* 2^(-1022), smallest normalized */ #define MAXNORM 1.7976931348623157081e308 /* 2^(1023)*(2-2^(-52)) */ @@ -78,11 +60,11 @@ void x86_fldcw _PROTO ((unsigned short cw)); int mpfr_set_machine_rnd_mode _PROTO ((mp_rnd_t)); void mpfr_test_init _PROTO ((void)); -double drand _PROTO ((void)); double drand48 _PROTO ((void)); long int lrand48 _PROTO ((void)); void srand48 _PROTO ((long int)); mp_limb_t randlimb _PROTO ((void)); +void randseed _PROTO ((unsigned int)); int ulp _PROTO ((double, double)); double dbl _PROTO ((double, int)); double Ulp _PROTO ((double)); diff --git a/tests/tabs.c b/tests/tabs.c index aa984f5d5..f0845f2d1 100644 --- a/tests/tabs.c +++ b/tests/tabs.c @@ -23,7 +23,9 @@ MA 02111-1307, USA. */ #include <stdlib.h> #include <float.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" +#include "mpfr-impl.h" #include "mpfr-test.h" static void @@ -45,7 +47,7 @@ check_inexact (void) mpfr_set_prec (x, p); mpfr_set_prec (absx, p); mpfr_random (x); - if (LONG_RAND () % 2) + if (randlimb () % 2) { mpfr_set (absx, x, GMP_RNDN); mpfr_neg (x, x, GMP_RNDN); @@ -124,7 +126,7 @@ main (int argc, char *argv[]) { do { - d = drand (); + d = DBL_RAND (); absd = ABS(d); } #ifdef HAVE_DENORMS @@ -132,7 +134,7 @@ main (int argc, char *argv[]) #else while (absd < DBL_MIN); #endif - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; mpfr_set_d (x, d, 0); mpfr_abs (x, x, rnd); dd = mpfr_get_d1 (x); diff --git a/tests/tacos.c b/tests/tacos.c index 35da08bed..00d866465 100644 --- a/tests/tacos.c +++ b/tests/tacos.c @@ -66,7 +66,7 @@ main (void) for (n=0; n<10; n++) { mpfr_random (x); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_acos (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tadd.c b/tests/tadd.c index fbe71bf99..2d13ffea0 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -468,7 +468,7 @@ check_inexact (void) abs(EXP(x)-EXP(u)) + max(prec(x), prec(u)) + 1 */ pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)) + 1; mpfr_set_prec (z, pz); - rnd = LONG_RAND () % 4; + rnd = randlimb () % 4; if (mpfr_add (z, x, u, rnd)) { fprintf (stderr, "z <- x + u should be exact\n"); @@ -615,7 +615,7 @@ main (int argc, char *argv[]) check53(3.14553393112021279444e-67, 3.14553401015952024126e-67, GMP_RNDU, 6.2910679412797336946e-67); - SEED_RAND (time(NULL)); + randseed (time(NULL)); check53(5.43885304644369509058e+185,-1.87427265794105342763e-57,GMP_RNDN, 5.4388530464436950905e185); check53(5.43885304644369509058e+185,-1.87427265794105342763e-57, GMP_RNDZ, diff --git a/tests/tagm.c b/tests/tagm.c index f2886f2a4..3476e7a3a 100644 --- a/tests/tagm.c +++ b/tests/tagm.c @@ -28,6 +28,8 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" +#if 0 +/* The following function is buggy and must not be used any longer. */ static double drand_agm (void) { @@ -42,6 +44,7 @@ drand_agm (void) return d; } +#endif #define check(a,b,r) check4(a,b,r,0.0) @@ -90,6 +93,7 @@ check_large (void) mpfr_clear(a); mpfr_clear(b); mpfr_clear(agm); } +#if 0 static void slave (int N, int p) { @@ -105,11 +109,12 @@ slave (int N, int p) b = drand_agm(); mpfr_set_d(ta, a, GMP_RNDN); mpfr_set_d(tb, b, GMP_RNDN); - mpfr_agm(tres, ta, tb, LONG_RAND() % 4 ); + mpfr_agm(tres, ta, tb, randlimb () % 4 ); } mpfr_clear(ta); mpfr_clear(ta); mpfr_clear(tres); printf("fin\n"); } +#endif static void check_nans (void) @@ -154,34 +159,34 @@ check_nans (void) int main (int argc, char* argv[]) { - int N; - - SEED_RAND (time(NULL)); - tests_start_mpfr (); + randseed (time(NULL)); + check_nans (); 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])); - return 0; + slave (atoi (argv[1]), atoi (argv[2])); + */ + return 0; } if (argc == 2) /* tagm N: N tests with random double's */ { - int i; + int N, i; double a, b; N = atoi (argv[1]); for (i = 0; i < N; i++) { - a = drand(); - b = drand(); - check(a, b, LONG_RAND() % 4); - } + a = DBL_RAND (); + b = DBL_RAND (); + check(a, b, randlimb () % 4); + } return 0; } else diff --git a/tests/tasin.c b/tests/tasin.c index b1fd9be4e..2d9320c64 100644 --- a/tests/tasin.c +++ b/tests/tasin.c @@ -1,6 +1,6 @@ /* Test file for mpfr_asin. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. Original version by Mathieu Dutour. This file is part of the MPFR Library. @@ -61,7 +61,7 @@ main (void) for (n = 0; n < 10; n++) { mpfr_random (x); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_asin (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tatan.c b/tests/tatan.c index 22f51e112..b36b16e8c 100644 --- a/tests/tatan.c +++ b/tests/tatan.c @@ -89,7 +89,7 @@ main (int argc, char *argv[]) for (n=0; n<N; n++) { mpfr_random (x); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_atan (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tcmp.c b/tests/tcmp.c index a1bf851be..54d411d26 100644 --- a/tests/tcmp.c +++ b/tests/tcmp.c @@ -22,6 +22,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" #include "mpfr-impl.h" #include "mpfr-test.h" @@ -162,8 +163,8 @@ main (void) for (i=0; i<1000000; ) { - x = drand(); - y = drand(); + x = DBL_RAND (); + y = DBL_RAND (); if (!Isnan(x) && !Isnan(y)) { i++; diff --git a/tests/tcmp2.c b/tests/tcmp2.c index 8e8adbffc..220b1c5a3 100644 --- a/tests/tcmp2.c +++ b/tests/tcmp2.c @@ -22,6 +22,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" #include "mpfr-impl.h" #include "mpfr-test.h" @@ -95,7 +96,7 @@ worst_cases (void) set_bit (y, i + 1, 0); for (j=0; j<64; j++) /* |v| = j */ { - b = random () % 2; + b = randlimb () % 2; set_bit (x, i + j + 2, b); set_bit (y, i + j + 2, b); diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index ad0bfae2d..23cfc78de 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -132,7 +132,7 @@ check_inexact (void) { mpfr_set_prec (x, px); mpfr_random (x); - do { u = LONG_RAND (); } while (u == 0); + do { u = randlimb (); } while (u == 0); for (py=2; py<300; py++) { mpfr_set_prec (y, py); diff --git a/tests/terf.c b/tests/terf.c index f51ab117b..2f5fdbaa6 100644 --- a/tests/terf.c +++ b/tests/terf.c @@ -51,8 +51,8 @@ test_generic (void) for (n=0; n<N; n++) { mpfr_random (x); - mpfr_mul_2exp (x, x, random () % 4, GMP_RNDN); - rnd = random () % 4; + mpfr_mul_2exp (x, x, randlimb () % 4, GMP_RNDN); + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_erf (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tests.c b/tests/tests.c index 5917cfdf0..b704cfa7e 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -129,28 +129,6 @@ tests_machine_prec_long_double (void) } -/* 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; -} - /* generate a random limb */ mp_limb_t randlimb (void) @@ -161,6 +139,17 @@ randlimb (void) return limb; } +void +randseed (unsigned int s) +{ + mpz_t t; + + mpz_init_set_ui (t, s); + gmp_randseed (RANDS, t); + mpz_clear (t); +} + + /* returns ulp(x) for x a 'normal' double-precision number */ double Ulp (double x) diff --git a/tests/texp.c b/tests/texp.c index dd71068ff..14dff25ac 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -192,7 +192,7 @@ compare_exp2_exp3 (int n) mpfr_set_prec (y, prec); mpfr_set_prec (z, prec); mpfr_random (x); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; mpfr_exp_2 (y, x, rnd); mpfr_exp3 (z, x, rnd); if (mpfr_cmp (y,z)) diff --git a/tests/tfma.c b/tests/tfma.c index d7f69bb1b..bdddb25bc 100644 --- a/tests/tfma.c +++ b/tests/tfma.c @@ -1,6 +1,6 @@ /* Test file for mpfr_fma. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -267,14 +267,14 @@ main (int argc, char *argv[]) mpfr_random (y); mpfr_random (z); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (x, x, GMP_RNDN); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (y, y, GMP_RNDN); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (z, z, GMP_RNDN); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (slong, 2 * prec); if (mpfr_mul (slong, x, y, rnd)) { diff --git a/tests/tgamma.c b/tests/tgamma.c index 6e557d5c8..fdf2a8480 100644 --- a/tests/tgamma.c +++ b/tests/tgamma.c @@ -72,7 +72,7 @@ main (void) for (n = 0; n < 4; n++) { mpfr_random (x); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_gamma (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tgeneric.c b/tests/tgeneric.c index 4be686bcd..b32c825a7 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -48,7 +48,7 @@ test_generic (int p0, int p1, int N) #else mpfr_random (x); #endif - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); compare = TEST_FUNCTION (y, x, rnd); if (mpfr_can_round (y, yprec, rnd, rnd, prec)) diff --git a/tests/thypot.c b/tests/thypot.c index 5caadd6ff..648548f3f 100644 --- a/tests/thypot.c +++ b/tests/thypot.c @@ -1,6 +1,6 @@ /* Test file for mpfr_hypot. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -108,11 +108,11 @@ main (int argc, char *argv[]) { mpfr_random(x1); mpfr_random(x2); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (x1, x1, GMP_RNDN); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (x2, x2, GMP_RNDN); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); compare =TEST_FUNCTION (y, x1,x2, rnd); diff --git a/tests/tlog.c b/tests/tlog.c index d7b89eb14..e0756375c 100644 --- a/tests/tlog.c +++ b/tests/tlog.c @@ -32,6 +32,8 @@ MA 02111-1307, USA. */ #define INT32 int #endif +#if 0 +/* The following function is buggy and must not be used any longer. */ static double drand_log (void) { @@ -47,6 +49,7 @@ drand_log (void) in double calculus in sqrt(u*v) */ return d; } +#endif #define check2(a,rnd,res) check1(a,rnd,res,1,0) #define check(a,r) check2(a,r,0.0) @@ -95,6 +98,7 @@ check3 (double d, unsigned long prec, mp_rnd_t rnd) mpfr_clear(x); mpfr_clear(y); } +#if 0 static void check4 (int N) { @@ -105,7 +109,7 @@ check4 (int N) for(i=0;i<N;i++) { d = drand_log (); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; cur = check1 (d, rnd, 0.0, 0, max); if (cur < 0) cur = -cur; @@ -130,11 +134,12 @@ slave (int N, int p) { d = drand_log(); mpfr_set_d (ta, d, GMP_RNDN); - mpfr_log (tres, ta, LONG_RAND() % 4 ); + mpfr_log (tres, ta, randlimb () % 4 ); } mpfr_clear(ta); mpfr_clear(tres); printf("fin\n"); } +#endif /* examples from Jean-Michel Muller and Vincent Lefevre Cf http://www.ens-lyon.fr/~jmmuller/Intro-to-TMD.htm @@ -256,12 +261,11 @@ special (void) int main (int argc, char *argv[]) { - int N = 0; double d; tests_start_mpfr (); - SEED_RAND (time(NULL)); + randseed (time(NULL)); if (argc==4) { /* tlog x prec rnd */ check3(atof(argv[1]), atoi(argv[2]), atoi(argv[3])); @@ -272,15 +276,17 @@ main (int argc, char *argv[]) { /* 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])); + /* slave(atoi(argv[1]),atoi(argv[2])); */ goto done; } if (argc==2) { /* tlog N: N tests with random double's */ + /* N=atoi(argv[1]); printf("Doing %d random tests in double precision\n", N); check4(N); + */ } else { diff --git a/tests/tmul.c b/tests/tmul.c index c05e9472a..6841552ee 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -209,7 +209,7 @@ check_exact (void) { mpfr_random (a); mpfr_random (b); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; inexact = mpfr_mul (c, a, b, rnd); if (mpfr_mul (d, a, b, rnd)) /* should be always exact */ { diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c index 9b1827bc6..a47a67d07 100644 --- a/tests/tmul_2exp.c +++ b/tests/tmul_2exp.c @@ -1,6 +1,6 @@ /* Test file for mpfr_mul_2exp. -Copyright 1999, 2001, 2002 Free Software Foundation. +Copyright 1999, 2001, 2002, 2003 Free Software Foundation. This file is part of the MPFR Library. @@ -23,6 +23,7 @@ MA 02111-1307, USA. */ #include <stdlib.h> #include <time.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" #include "mpfr-impl.h" #include "mpfr-test.h" @@ -47,7 +48,7 @@ main (int argc, char *argv[]) mpfr_mul_2exp (w, w, 10, GMP_RNDZ); if (!MPFR_IS_NAN(w)) { fprintf(stderr, "NaN != NaN"); exit(-1); } - SEED_RAND (time(NULL)); + randseed (time(NULL)); for (k = 0; k < 100000; k++) { x = DBL_RAND (); mpfr_set_d (w, x, 0); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index fd6e08e19..30111acce 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -40,7 +40,7 @@ check_inexact (mp_prec_t p) mpfr_init (y); mpfr_init2 (z, p + mp_bits_per_limb); mpfr_random (x); - u = LONG_RAND(); + u = randlimb (); if (mpfr_mul_ui (z, x, u, GMP_RNDN)) { fprintf (stderr, "Error: result should be exact\n"); diff --git a/tests/tout_str.c b/tests/tout_str.c index c694948d6..bfe2e7fc0 100644 --- a/tests/tout_str.c +++ b/tests/tout_str.c @@ -137,20 +137,20 @@ main (int argc, char *argv[]) check (7.02293374921793516813e-84, GMP_RNDN, 10); /* random tests */ - SEED_RAND (time(NULL)); + randseed (time(NULL)); for (i=0;i<N;i++) { do { - d = drand (); + d = DBL_RAND (); } #ifdef HAVE_DENORMS while (0); #else while (ABS(d) < DBL_MIN); #endif - r = LONG_RAND() % 4; - p = 2 + LONG_RAND() % 35; + r = randlimb () % 4; + p = 2 + randlimb () % 35; check (d, r, p); } diff --git a/tests/tpow.c b/tests/tpow.c index d94af9dc4..a725d3a7d 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -82,7 +82,7 @@ check_inexact (mp_prec_t p) mpfr_init (z); mpfr_init (t); mpfr_random (x); - u = LONG_RAND() % 2; + u = randlimb () % 2; for (q=2; q<=p; q++) for (rnd=0; rnd<4; rnd++) { diff --git a/tests/tpow3.c b/tests/tpow3.c index 8cf2dffc5..ba5100ef3 100644 --- a/tests/tpow3.c +++ b/tests/tpow3.c @@ -69,9 +69,9 @@ main (int argc, char *argv[]) mpfr_random (x); mpfr_random (s); - if (random() % 2) + if (randlimb () % 2) mpfr_neg (s, s, GMP_RNDN); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); compare = mpfr_pow (y, x, s, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/trint.c b/tests/trint.c index 0f07b22b9..172d09490 100644 --- a/tests/trint.c +++ b/tests/trint.c @@ -1,6 +1,6 @@ /* Test file for mpfr_trunc, mpfr_floor, mpfr_ceil, mpfr_round. -Copyright 2002 Free Software Foundation. +Copyright 2002, 2003 Free Software Foundation. This file is part of the MPFR Library. @@ -47,7 +47,7 @@ main (void) /* z has exactly s bits */ mpz_mul_2exp (z, z, 1); - if (LONG_RAND () % 2) + if (randlimb () % 2) mpz_add_ui (z, z, 1); mpfr_set_prec (x, s); mpfr_set_prec (t, s); diff --git a/tests/tset.c b/tests/tset.c index e103ac796..62690881d 100644 --- a/tests/tset.c +++ b/tests/tset.c @@ -56,7 +56,7 @@ main (void) { mpfr_set_prec (x, p); mpfr_random (x); - if (LONG_RAND () % 2) + if (randlimb () % 2) mpfr_neg (x, x, GMP_RNDN); for (q=2; q<2*p; q++) { diff --git a/tests/tset_d.c b/tests/tset_d.c index 84a9e922d..353986c81 100644 --- a/tests/tset_d.c +++ b/tests/tset_d.c @@ -24,6 +24,7 @@ MA 02111-1307, USA. */ #include <float.h> #include <time.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" #include "mpfr-test.h" @@ -95,7 +96,7 @@ main (int argc, char *argv[]) mpfr_get_d1 (x)); exit(1); } - SEED_RAND (time(NULL)); + randseed (time(NULL)); mpfr_set_d(x, 8.06294740693074521573e-310, 0); d = -6.72658901114033715233e-165; mpfr_set_d(x, d, 0); @@ -109,7 +110,7 @@ main (int argc, char *argv[]) { do { - d = drand(); + d = DBL_RAND (); } #ifdef HAVE_DENORMS while (0); diff --git a/tests/tset_f.c b/tests/tset_f.c index 7506398cb..f178320cb 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_f. -Copyright 1999, 2001, 2002 Free Software Foundation, Inc. +Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -45,9 +45,9 @@ main (void) mpfr_set_prec (x, 100); mpfr_set_f (x, y, GMP_RNDN); - SEED_RAND (time(NULL)); + randseed (time(NULL)); mpf_random2(y, 10, 0); - mpfr_set_f(x, y, LONG_RAND() & 3); + mpfr_set_f(x, y, randlimb () & 3); /* bug found by Jean-Pierre Merlet */ mpfr_set_prec(x, 256); @@ -73,7 +73,7 @@ main (void) for (k = 1; k <= 100000; k++) { - pr = 2 + (LONG_RAND()&255); + pr = 2 + (randlimb () & 255); mpf_set_prec (z, pr); mpf_random2 (z, z->_mp_prec, 0); mpfr_init2 (x, pr); diff --git a/tests/tset_si.c b/tests/tset_si.c index 36771751c..3564aed5b 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_si and mpfr_set_ui. -Copyright 1999, 2001, 2002 Free Software Foundation, Inc. +Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -23,6 +23,7 @@ MA 02111-1307, USA. */ #include <stdlib.h> #include <time.h> #include "gmp.h" +#include "gmp-impl.h" #include "mpfr.h" #include "mpfr-impl.h" #include "mpfr-test.h" @@ -39,13 +40,13 @@ main (int argc, char *argv[]) mpfr_init2(x, 100); - SEED_RAND (time(NULL)); + randseed (time(NULL)); N = (argc==1) ? 1000000 : atoi(argv[1]); for (k = 1; k <= N; k++) { - z = random() - (1 << 30); + z = (long) (randlimb () & LONG_MAX) + LONG_MIN/2; inex = mpfr_set_si(x, z, GMP_RNDZ); d = (long) mpfr_get_d1 (x); if (d != z) { @@ -62,7 +63,7 @@ main (int argc, char *argv[]) for (k = 1; k <= N; k++) { - zl = random(); + zl = randlimb (); inex = mpfr_set_ui (x, zl, GMP_RNDZ); dl = (unsigned long) mpfr_get_d1 (x); if (dl != zl) { diff --git a/tests/tset_str.c b/tests/tset_str.c index e200c18a4..ca8e075f6 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -22,6 +22,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <limits.h> #include <time.h> #include "gmp.h" #include "gmp-impl.h" @@ -53,13 +54,13 @@ main (int argc, char *argv[]) mpfr_init2 (x, 2); - SEED_RAND (time(NULL)); + randseed (time(NULL)); nc = (argc > 1) ? atoi(argv[1]) : 53; if (nc < 100) nc = 100; - bd = LONG_RAND() & 8; + bd = randlimb () & 8; str2 = str = (*__gmp_allocate_func) (nc * sizeof(char)); @@ -67,7 +68,7 @@ main (int argc, char *argv[]) { for(k = 1; k <= bd; k++) - *(str2++) = (LONG_RAND() & 1) + '0'; + *(str2++) = (randlimb () & 1) + '0'; } else *(str2++) = '0'; @@ -75,10 +76,10 @@ main (int argc, char *argv[]) *(str2++) = '.'; for (k = 1; k < nc - 17 - bd; k++) - *(str2++) = '0' + (LONG_RAND() & 1); + *(str2++) = '0' + (randlimb () & 1); *(str2++) = 'e'; - sprintf (str2, "%d", (int) LONG_RAND() - (1 << 30)); + sprintf (str2, "%d", (int) (randlimb () & INT_MAX) + INT_MIN/2); mpfr_set_prec (x, nc + 10); mpfr_set_str_raw (x, str); @@ -151,8 +152,8 @@ main (int argc, char *argv[]) for (i=0;i<100000;i++) { mpfr_random (x); - k = LONG_RAND() % 4; - logbase = (LONG_RAND() % 5) + 1; + k = randlimb () % 4; + logbase = (randlimb () % 5) + 1; base = 1 << logbase; /* Warning: the number of bits needed to print exactly a number of 'prec' bits in base 2^logbase may be greater than ceil(prec/logbase), diff --git a/tests/tset_z.c b/tests/tset_z.c index 0acb9af3a..0598e6c44 100644 --- a/tests/tset_z.c +++ b/tests/tset_z.c @@ -21,6 +21,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> +#include <limits.h> #include <time.h> #include "gmp.h" #include "mpfr.h" @@ -69,10 +70,10 @@ main (int argc, char *argv[]) tests_start_mpfr (); check_large(); - SEED_RAND (time(NULL)); + randseed (time(NULL)); check(0, 0); for (j=0; j<1000000; j++) - check(LONG_RAND(), LONG_RAND()%4); + check(randlimb () & LONG_MAX, randlimb () % 4); tests_end_mpfr (); return 0; diff --git a/tests/tsqrt.c b/tests/tsqrt.c index bd161faa3..478a3e3fc 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -225,7 +225,7 @@ check_inexact (mp_prec_t p) mpfr_init2 (y, p); mpfr_init2 (z, 2*p); mpfr_random (x); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; inexact = mpfr_sqrt (y, x, rnd); if (mpfr_mul (z, y, y, rnd)) /* exact since prec(z) = 2*prec(y) */ { diff --git a/tests/tsub.c b/tests/tsub.c index ffff6e901..4039bbdf1 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -300,7 +300,7 @@ check_two_sum (mp_prec_t p) mpfr_random (y); if (mpfr_cmpabs (x, y) < 0) mpfr_swap (x, y); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; rnd = GMP_RNDN; inexact = mpfr_sub (u, x, y, GMP_RNDN); mpfr_sub (v, u, x, GMP_RNDN); @@ -370,7 +370,7 @@ check_inexact (void) : MPFR_EXP(u)-MPFR_EXP(x); pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)); mpfr_set_prec (z, pz); - rnd = LONG_RAND () % 4; + rnd = randlimb () % 4; if (mpfr_sub (z, x, u, rnd)) { fprintf (stderr, "z <- x - u should be exact\n"); diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index 532817c13..5fbeb4a18 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -74,11 +74,11 @@ check_two_sum (mp_prec_t p) mpfr_init2 (w, p); do { - x = LONG_RAND (); + x = randlimb (); } while (x < 1); mpfr_random (y); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; rnd = GMP_RNDN; inexact = mpfr_sub_ui (u, y, x, GMP_RNDN); mpfr_add_ui (v, u, x, GMP_RNDN); diff --git a/tests/tui_div.c b/tests/tui_div.c index deacaf669..2c124db29 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -69,7 +69,7 @@ check_inexact (void) { mpfr_set_prec (x, px); mpfr_random (x); - u = LONG_RAND (); + u = randlimb (); for (py=2; py<300; py++) { mpfr_set_prec (y, py); diff --git a/tests/tui_pow.c b/tests/tui_pow.c index 35b836506..ff5d65950 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -1,6 +1,6 @@ /* Test file for mpfr_ui_pow. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -22,6 +22,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> +#include <limits.h> #include "gmp.h" #include "gmp-impl.h" #include "mpfr.h" @@ -40,7 +41,7 @@ main (int argc, char *argv[]) mpfr_init (x); mpfr_init (y); - n = abs(random()); + n = randlimb (); MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); @@ -96,9 +97,9 @@ main (int argc, char *argv[]) for (n=0; n<N; n++) { int nt; - nt = abs(random()); + nt = randlimb () & INT_MAX; mpfr_random (x); - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); compare = mpfr_ui_pow (y, nt, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tui_sub.c b/tests/tui_sub.c index 231a228f5..f53ecbf6f 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -165,11 +165,11 @@ check_two_sum (mp_prec_t p) mpfr_init2 (w, p); do { - x = LONG_RAND (); + x = randlimb (); } while (x < 1); mpfr_random (y); - rnd = LONG_RAND() % 4; + rnd = randlimb () % 4; rnd = GMP_RNDN; inexact = mpfr_ui_sub (u, x, y, GMP_RNDN); mpfr_sub_ui (v, u, x, GMP_RNDN); diff --git a/tests/tzeta.c b/tests/tzeta.c index bb496c455..08e1b3b56 100644 --- a/tests/tzeta.c +++ b/tests/tzeta.c @@ -54,12 +54,12 @@ test_generic () { mpfr_random (x); /* x is in [0, 1[ */ mpfr_add_ui (x, x, 1, GMP_RNDN); - e = random () % 5; + e = randlimb () % 5; mpfr_div_2exp (x, x, 1, GMP_RNDN); /* now in [1/2, 1[ */ mpfr_mul_2exp (x, x, e, GMP_RNDN); /* now in [2^(e-1), 2^e[ */ - if (random () % 2) + if (randlimb () % 2) mpfr_ui_sub (x, 1, x, GMP_RNDN); /* now less or equal to 1/2 */ - rnd = random () % 4; + rnd = randlimb () % 4; mpfr_set_prec (y, yprec); mpfr_zeta (y, x, rnd); err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; |