summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2002-03-21 15:35:48 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2002-03-21 15:35:48 +0000
commit7563e1b2676d837c96ed25e361a5e9dd714567dc (patch)
tree33906130053295abaaf74e98f81b794b8eece54b
parent0df22d500aef3b11656722b40e21890ee1a5c531 (diff)
downloadmpfr-7563e1b2676d837c96ed25e361a5e9dd714567dc.tar.gz
replaced rand/lrand48, drand48, srand/srand48 by macros
LONG_RAND, DBL_RAND, SEED_RAND and time(NULL) by getpid() git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1762 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tabs.c4
-rw-r--r--tests/tadd.c29
-rw-r--r--tests/tadd_ui.c12
-rw-r--r--tests/tagm.c20
-rw-r--r--tests/tcmp2.c4
-rw-r--r--tests/tdiv.c4
-rw-r--r--tests/tdiv_ui.c8
-rw-r--r--tests/texp.c9
-rw-r--r--tests/tget_d.c6
-rw-r--r--tests/tget_str.c2
-rw-r--r--tests/tlog.c16
-rw-r--r--tests/tmul.c6
-rw-r--r--tests/tmul_2exp.c10
-rw-r--r--tests/tmul_ui.c3
-rw-r--r--tests/tout_str.c9
-rw-r--r--tests/tpow.c3
-rw-r--r--tests/trandom.c5
-rw-r--r--tests/trint.c3
-rw-r--r--tests/tset.c3
-rw-r--r--tests/tset_d.c4
-rw-r--r--tests/tset_f.c9
-rw-r--r--tests/tset_q.c10
-rw-r--r--tests/tset_si.c3
-rw-r--r--tests/tset_str.c17
-rw-r--r--tests/tset_z.c5
-rw-r--r--tests/tsqrt.c6
-rw-r--r--tests/tsqrt_ui.c6
-rw-r--r--tests/tsub.c4
-rw-r--r--tests/tsub_ui.c16
-rw-r--r--tests/tui_div.c8
-rw-r--r--tests/tui_sub.c12
31 files changed, 125 insertions, 131 deletions
diff --git a/tests/tabs.c b/tests/tabs.c
index 736c2335f..97ca29f7e 100644
--- a/tests/tabs.c
+++ b/tests/tabs.c
@@ -44,7 +44,7 @@ check_inexact (void)
mpfr_set_prec (x, p);
mpfr_set_prec (absx, p);
mpfr_random (x);
- if (rand () % 2)
+ if (LONG_RAND () % 2)
{
mpfr_set (absx, x, GMP_RNDN);
mpfr_neg (x, x, GMP_RNDN);
@@ -125,7 +125,7 @@ main (int argc, char *argv[])
for (k = 1; k <= n; k++)
{
d = drand();
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
mpfr_set_d(x, d, 0);
mpfr_abs(x, x, rnd);
dd = mpfr_get_d(x);
diff --git a/tests/tadd.c b/tests/tadd.c
index 69bbed11a..e62ed4d17 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -101,7 +101,7 @@ check3 (double x, double y, mp_rnd_t rnd_mode)
{
double z1,z2; mpfr_t xx,yy; int neg;
- neg = rand() % 2;
+ neg = LONG_RAND() % 2;
mpfr_init2(xx, 53);
mpfr_init2(yy, 53);
mpfr_set_d(xx, x, rnd_mode);
@@ -129,7 +129,7 @@ check4 (double x, double y, mp_rnd_t rnd_mode)
mpfr_t xx, yy;
int neg;
- neg = rand() % 2;
+ neg = LONG_RAND() % 2;
mpfr_init2(xx, 53);
mpfr_init2(yy, 53);
mpfr_set_d(xx, x, rnd_mode);
@@ -158,7 +158,7 @@ check5 (double x, mp_rnd_t rnd_mode)
mpfr_init2(xx, 53);
mpfr_init2(yy, 53);
- neg = rand() % 2;
+ neg = LONG_RAND() % 2;
mpfr_set_d(xx, x, rnd_mode);
if (neg) mpfr_sub(xx, xx, xx, rnd_mode);
else mpfr_add(xx, xx, xx, rnd_mode);
@@ -600,7 +600,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 = rand () % 4;
+ rnd = LONG_RAND () % 4;
if (mpfr_add (z, x, u, rnd))
{
fprintf (stderr, "z <- x + u should be exact\n");
@@ -704,7 +704,8 @@ main (int argc, char *argv[])
9.0969267746123943065e196);
check53(3.14553393112021279444e-67, 3.14553401015952024126e-67, GMP_RNDU,
6.2910679412797336946e-67);
- srand(getpid());
+
+ SEED_RAND (getpid ());
check53(5.43885304644369509058e+185,-1.87427265794105342763e-57,GMP_RNDN,
5.4388530464436950905e185);
check53(5.43885304644369509058e+185,-1.87427265794105342763e-57, GMP_RNDZ,
@@ -842,20 +843,20 @@ main (int argc, char *argv[])
y = drand();
if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check(x, y, rnd, prec, prec, prec, 0.0);
}
}
/* tests with random precisions */
for (i=0;i<N;i++) {
int px, py, pz;
- px = 53 + (rand() % 64);
- py = 53 + (rand() % 64);
- pz = 53 + (rand() % 64);
- rnd_mode = rand() % 4;
+ px = 53 + (LONG_RAND() % 64);
+ py = 53 + (LONG_RAND() % 64);
+ pz = 53 + (LONG_RAND() % 64);
+ rnd_mode = LONG_RAND() % 4;
do { x = drand(); } while (isnan(x));
do { y = drand(); } while (isnan(y));
- check2(x,px,y,py,pz,rnd_mode);
+ check2 (x, px, y, py, pz, rnd_mode);
}
/* Checking mpfr_add(x, x, y) with prec=53 */
for (i=0;i<N;i++) {
@@ -863,7 +864,7 @@ main (int argc, char *argv[])
y = drand();
if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check3(x, y, rnd);
}
}
@@ -873,7 +874,7 @@ main (int argc, char *argv[])
y = drand();
if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check4(x, y, rnd);
}
}
@@ -881,7 +882,7 @@ main (int argc, char *argv[])
for (i=0;i<N;i++) {
do { x = drand(); } while ((ABS(x)<2.2e-307) || (ABS(x)>0.8e308));
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check5(x, rnd);
}
#endif
diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c
index 778062ad2..394a31548 100644
--- a/tests/tadd_ui.c
+++ b/tests/tadd_ui.c
@@ -28,9 +28,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
-#ifdef __mips
-#include <sys/fpu.h>
-#endif
+#include "mpfr-test.h"
void check3 _PROTO((double, unsigned long, unsigned int, double));
void special _PROTO((void));
@@ -90,15 +88,15 @@ main (int argc, char *argv[])
set_fpc_csr(exp.fc_word);
#endif
- srand(getpid());
+ SEED_RAND (getpid ());
N = (argc<2) ? 1000000 : atoi(argv[1]);
rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
for (i=0;i<1000000;i++) {
- x = drand48();
- y = lrand48();
+ x = drand();
+ y = LONG_RAND();
if (ABS(x)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check(x, y, rnd);
}
}
diff --git a/tests/tagm.c b/tests/tagm.c
index a897ba8fe..a87c524d4 100644
--- a/tests/tagm.c
+++ b/tests/tagm.c
@@ -35,16 +35,14 @@ void check_large _PROTO((void));
void slave _PROTO((int, int));
double
-drand_agm(void)
+drand_agm (void)
{
double d; long int *i;
i = (long int*) &d;
do {
- i[0] = lrand48();
- i[1] = lrand48();
- /*if (lrand48()%2) d=-d; */ /* generates negative numbers */
- /* useless here */
+ i[0] = LONG_RAND();
+ i[1] = LONG_RAND();
} while ((d<1e-153)||(d>1e153)); /* to avoid underflow or overflow
in double calculus in sqrt(u*v) */
@@ -132,16 +130,16 @@ slave (int N, int p)
double a,b;
mpfr_t ta, tb, tres;
- srand48(getpid());
+ SEED_RAND (getpid ());
mpfr_init2(ta, 53);
mpfr_init2(tb, 53);
mpfr_init2(tres, p);
for(i=0;i<N;i++) {
- a=drand_agm();
- b=drand_agm();
+ a = drand_agm();
+ b = drand_agm();
mpfr_set_d(ta, a, GMP_RNDN);
mpfr_set_d(tb, b, GMP_RNDN);
- mpfr_agm(tres, ta, tb, rand() % 4 );
+ mpfr_agm(tres, ta, tb, LONG_RAND() % 4 );
}
mpfr_clear(ta); mpfr_clear(ta); mpfr_clear(tres);
printf("fin\n");
@@ -163,12 +161,12 @@ main (int argc, char* argv[])
int i;
double a,b;
- srand48(getpid());
+ SEED_RAND (getpid ());
N = atoi(argv[1]);
for (i=0;i<N;i++) {
a = drand();
b = drand();
- check(a, b, rand() % 4);
+ check(a, b, LONG_RAND() % 4);
}
return 0;
}
diff --git a/tests/tcmp2.c b/tests/tcmp2.c
index ef5a6bb3a..1bb2db4e1 100644
--- a/tests/tcmp2.c
+++ b/tests/tcmp2.c
@@ -302,8 +302,8 @@ main (void)
x /= 2.0;
}
for (j=0; j<100000; j++) {
- x = drand48();
- y = drand48();
+ x = DBL_RAND ();
+ y = DBL_RAND ();
if (x<y) { z=x; x=y; y=z; }
if (y != 0.0 && y != -0.0) tcmp2(x, y, -1);
}
diff --git a/tests/tdiv.c b/tests/tdiv.c
index 2ac52587d..95a65413c 100644
--- a/tests/tdiv.c
+++ b/tests/tdiv.c
@@ -443,12 +443,12 @@ main (int argc, char *argv[])
#ifdef TEST
N = (argc>1) ? atoi(argv[1]) : 100000;
- srand48(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<N;i++) {
do { n = drand(); d = drand(); e = ABS(n)/ABS(d); }
/* smallest normalized is 2^(-1022), largest is 2^(1023)*(2-2^(-52)) */
while (e>=MAXNORM || e<MINNORM);
- check4(n, d, rand() % 4, 53, 0.0);
+ check4(n, d, LONG_RAND() % 4, 53, 0.0);
}
#endif
diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c
index e3954e4cf..68299c4cb 100644
--- a/tests/tdiv_ui.c
+++ b/tests/tdiv_ui.c
@@ -135,7 +135,7 @@ check_inexact (void)
{
mpfr_set_prec (x, px);
mpfr_random (x);
- do { u = lrand48 (); } while (u == 0);
+ do { u = LONG_RAND (); } while (u == 0);
for (py=2; py<300; py++)
{
mpfr_set_prec (y, py);
@@ -177,11 +177,11 @@ main (int argc, char **argv)
#ifdef TEST
int i; unsigned long u; double d;
- srand(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<1000000;i++) {
- do { u = lrand48(); } while (u==0);
+ do { u = LONG_RAND(); } while (u==0);
do { d = drand(); } while (ABS(d/u)<2.2e-307);
- check(d, u, rand() % 4, 0.0);
+ check(d, u, LONG_RAND() % 4, 0.0);
}
#endif
diff --git a/tests/texp.c b/tests/texp.c
index 1b737aa07..d50429ddb 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -187,7 +187,7 @@ compare_exp2_exp3 (int n)
mpfr_set_prec (y, prec);
mpfr_set_prec (z, prec);
mpfr_random (x);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
mpfr_exp_2 (y, x, rnd);
mpfr_exp3 (z, x, rnd);
if (mpfr_cmp (y,z))
@@ -228,7 +228,6 @@ main (int argc, char *argv[])
exit(1);
}
- srand(getpid());
compare_exp2_exp3(500);
check_worst_cases();
check3(0.0, GMP_RNDU, 1.0);
@@ -271,7 +270,7 @@ main (int argc, char *argv[])
check3(5.16239362447650933063e+02, GMP_RNDZ, 1.5845518406744492105e224);
check3(6.00812634798592370977e-01, GMP_RNDN, 1.823600119339019443);
#ifdef TEST
- srand48(getpid());
+ SEED_RAND (getpid());
N = (argc==1) ? 0 : atoi(argv[1]);
lo = (argc>=3) ? atof(argv[2]) : -7.083964185e2;
hi = (argc>=4) ? atof(argv[3]) : 7.097827129e2;
@@ -279,8 +278,8 @@ main (int argc, char *argv[])
/* select d such that exp(d) can be represented as a normalized
machine double-precision number,
i.e. 2^(-1022) <= exp(d) <= 2^(1023)*(2-2^(-52)) */
- d = lo + (hi-lo)*drand48();
- e = check(d, rand() % 4);
+ d = lo + (hi-lo)*DBL_RAND();
+ e = check(d, LONG_RAND() % 4);
s += e;
if (e>maxe) maxe=e;
}
diff --git a/tests/tget_d.c b/tests/tget_d.c
index 3e23cb96d..1b31af5a8 100644
--- a/tests/tget_d.c
+++ b/tests/tget_d.c
@@ -64,7 +64,7 @@ main (void)
mpfr_div_2ui(y, half, j, GMP_RNDZ);
(sj ? mpfr_sub : mpfr_add)(y, x, y, GMP_RNDZ);
- exp = (rand() % 47) - 23;
+ exp = (LONG_RAND() % 47) - 23;
mpfr_mul_2si(y, y, exp, GMP_RNDZ);
if (mpfr_inexflag_p())
{
@@ -75,14 +75,14 @@ main (void)
}
dd = si != sj ? di - dj : di + dj;
d = si ? 0.5 - dd : 0.5 + dd;
- if ((rand() / 1024) & 1)
+ if ((LONG_RAND() / 1024) & 1)
{
c = mpfr_get_d2(y, rnd_mode);
f = "mpfr_get_d2";
}
else
{
- exp = (rand() % 47) - 23;
+ exp = (LONG_RAND() % 47) - 23;
c = mpfr_get_d3(y, exp, rnd_mode);
f = "mpfr_get_d3";
if (si) /* then real d < 0.5 */
diff --git a/tests/tget_str.c b/tests/tget_str.c
index 8e826aa00..0e984eef7 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -108,7 +108,7 @@ main (int argc, char *argv[])
#ifdef TEST
int i; double d;
- srand(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<100000;i++) {
do { d = drand(); } while (isnan(d));
check(d, GMP_RNDN);
diff --git a/tests/tlog.c b/tests/tlog.c
index b327d6dad..8e4a6fa84 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -49,8 +49,8 @@ drand_log (void)
i = (INT32*) &d;
do {
- i[0] = lrand48();
- i[1] = lrand48();
+ i[0] = LONG_RAND();
+ i[1] = LONG_RAND();
} while ((d<1e-153) || (d>1e153)); /* to avoid underflow or overflow
in double calculus in sqrt(u*v) */
return d;
@@ -119,8 +119,8 @@ check4 (int N)
mp_rnd_t rnd;
for(i=0;i<N;i++) {
- d=drand_log();
- rnd = rand() % 4;
+ d = drand_log ();
+ rnd = LONG_RAND() % 4;
cur=check1 (d, rnd, 0.0, 0, max);
if (cur<0)
cur = -cur;
@@ -142,9 +142,9 @@ slave (int N, int p)
mpfr_init2(ta, 53);
mpfr_init2(tres, p);
for(i=0;i<N;i++) {
- d=drand_log();
- mpfr_set_d(ta, d, GMP_RNDN);
- mpfr_log(tres, ta,rand() % 4 );
+ d = drand_log();
+ mpfr_set_d (ta, d, GMP_RNDN);
+ mpfr_log (tres, ta, LONG_RAND() % 4 );
}
mpfr_clear(ta); mpfr_clear(tres);
printf("fin\n");
@@ -271,7 +271,7 @@ main (int argc, char *argv[])
{
int N=0;
- srand48(getpid());
+ SEED_RAND (getpid ());
if (argc==4) { /* tlog x prec rnd */
check3(atof(argv[1]), atoi(argv[2]), atoi(argv[3]));
return 0;
diff --git a/tests/tmul.c b/tests/tmul.c
index 9b4fc8b69..f7e3b36a3 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -209,7 +209,7 @@ check_exact (void)
{
mpfr_random (a);
mpfr_random (b);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
inexact = mpfr_mul (c, a, b, rnd);
if (mpfr_mul (d, a, b, rnd)) /* should be always exact */
{
@@ -377,7 +377,7 @@ main (int argc, char *argv[])
check_max();
check_min();
#ifdef TEST
- srand48(getpid());
+ SEED_RAND (getpid ());
prec = (argc<2) ? 53 : atoi(argv[1]);
rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
for (i=0;i<1000000;) {
@@ -386,7 +386,7 @@ main (int argc, char *argv[])
z = x*y; if (z<0) z=-z;
if (z<1e+308 && z>1e-308) /* don't test overflow/underflow for now */
{ i++;
- check(x, y, (rnd_mode==-1) ? lrand48()%4 : rnd_mode,
+ check(x, y, (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode,
prec, prec, prec, 0.0);
}
}
diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c
index 73cf61696..1d3758460 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2exp.c
@@ -21,10 +21,10 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
/* checks that x*y gives the same results in double
and with mpfr with 53 bits of precision */
@@ -44,11 +44,11 @@ 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 (getpid ());
for (k = 0; k < 100000; k++) {
- srand48(time(NULL));
- x = drand48();
- mpfr_set_d(w, x, 0);
- mpfr_mul_2exp(w, w, 10, GMP_RNDZ);
+ x = DBL_RAND ();
+ mpfr_set_d (w, x, 0);
+ mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
if (x != (z = mpfr_get_d(w)/1024))
{
fprintf(stderr, "%f != %f\n", x, z);
diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c
index f07620cc9..3f269519a 100644
--- a/tests/tmul_ui.c
+++ b/tests/tmul_ui.c
@@ -26,6 +26,7 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
void check_inexact _PROTO((mp_prec_t));
@@ -42,7 +43,7 @@ check_inexact (mp_prec_t p)
mpfr_init (y);
mpfr_init2 (z, p + mp_bits_per_limb);
mpfr_random (x);
- u = lrand48();
+ u = LONG_RAND();
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 1695ccce0..481b67362 100644
--- a/tests/tout_str.c
+++ b/tests/tout_str.c
@@ -23,7 +23,6 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <unistd.h>
#include "gmp.h"
#include "mpfr.h"
@@ -131,15 +130,15 @@ main (int argc, char *argv[])
check(7.02293374921793516813e-84, GMP_RNDN, 10);
/* random tests */
- srand(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<N;i++)
{
do
{
- d = drand();
+ d = drand ();
} while (isnan(d));
- r = rand() % 4;
- p = 2 + rand() % 35;
+ r = LONG_RAND() % 4;
+ p = 2 + LONG_RAND() % 35;
check (d, r, p);
}
diff --git a/tests/tpow.c b/tests/tpow.c
index a023bb956..9009eda40 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
+#include "mpfr-test.h"
void check_pow_ui _PROTO ((void));
void check_inexact _PROTO ((mp_prec_t));
@@ -78,7 +79,7 @@ check_inexact (mp_prec_t p)
mpfr_init (z);
mpfr_init (t);
mpfr_random (x);
- u = lrand48() % 2;
+ u = LONG_RAND() % 2;
for (q=2; q<=p; q++)
for (rnd=0; rnd<4; rnd++)
{
diff --git a/tests/trandom.c b/tests/trandom.c
index 1499fc756..fc784f41f 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -22,7 +22,6 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
-#include <time.h>
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
@@ -134,8 +133,8 @@ test_urandomb (unsigned long nbtests, unsigned long prec, int verbose)
tab = (int *) malloc (size_tab * sizeof(int));
for (k = 0; k < size_tab; ++k) tab[k] = 0;
- gmp_randinit(state, GMP_RAND_ALG_LC, 128);
- gmp_randseed_ui(state, (unsigned long int)time(NULL));
+ gmp_randinit (state, GMP_RAND_ALG_LC, 128);
+ gmp_randseed_ui (state, getpid ());
for (k = 0; k < nbtests; k++) {
mpfr_urandomb(x, state);
diff --git a/tests/trint.c b/tests/trint.c
index def8e765b..e454c5cd3 100644
--- a/tests/trint.c
+++ b/tests/trint.c
@@ -23,6 +23,7 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
@@ -44,7 +45,7 @@ main (void)
/* z has exactly s bits */
mpz_mul_2exp (z, z, 1);
- if (rand () % 2)
+ if (LONG_RAND () % 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 f9a2b3911..4d8be37fe 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
int
main (void)
@@ -54,7 +55,7 @@ main (void)
{
mpfr_set_prec (x, p);
mpfr_random (x);
- if (rand () % 2)
+ if (LONG_RAND () % 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 95ef9e26d..165eed0db 100644
--- a/tests/tset_d.c
+++ b/tests/tset_d.c
@@ -21,7 +21,6 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-test.h"
@@ -78,7 +77,8 @@ main (int argc, char *argv[])
printf("Error: get_d o set_d <> identity for d = %1.20e %1.20e\n",d,
mpfr_get_d(x)); exit(1);
}
- srand48(time(NULL));
+
+ SEED_RAND (getpid ());
mpfr_set_d(x, 8.06294740693074521573e-310, 0);
d = -6.72658901114033715233e-165;
mpfr_set_d(x, d, 0);
diff --git a/tests/tset_f.c b/tests/tset_f.c
index f2bb6ff88..351f1fd15 100644
--- a/tests/tset_f.c
+++ b/tests/tset_f.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set_f.
-Copyright 1999, 2001 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -23,7 +23,6 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include "gmp.h"
#include "mpfr.h"
-#include "time.h"
#include "mpfr-test.h"
int
@@ -43,9 +42,9 @@ main (void)
mpfr_set_prec (x, 100);
mpfr_set_f (x, y, GMP_RNDN);
- srandom((int)time(NULL));
+ SEED_RAND (getpid ());
mpf_random2(y, 10, 0);
- mpfr_set_f(x, y, rand() & 3);
+ mpfr_set_f(x, y, LONG_RAND() & 3);
/* bug found by Jean-Pierre Merlet */
mpfr_set_prec(x, 256);
@@ -71,7 +70,7 @@ main (void)
for (k = 1; k <= 100000; k++)
{
- pr = 2 + (rand()&255);
+ pr = 2 + (LONG_RAND()&255);
mpf_set_prec (z, pr);
mpf_random2 (z, z->_mp_prec, 0);
mpfr_init2 (x, pr);
diff --git a/tests/tset_q.c b/tests/tset_q.c
index a39cf3776..44ac664a2 100644
--- a/tests/tset_q.c
+++ b/tests/tset_q.c
@@ -85,12 +85,12 @@ main (void)
double y;
unsigned char rnd;
- srand48(getpid());
+ SEED_RAND(getpid());
for (i=0;i<1000000;i++) {
- n = lrand48();
- d = lrand48();
- if (lrand48()%2) n = -n;
- rnd = lrand48() % 4;
+ n = LONG_RAND();
+ d = LONG_RAND();
+ if (LONG_RAND()%2) n = -n;
+ rnd = LONG_RAND() % 4;
y = (double) n / d;
check(n, d, rnd, y);
}
diff --git a/tests/tset_si.c b/tests/tset_si.c
index 571cb3145..c1333879b 100644
--- a/tests/tset_si.c
+++ b/tests/tset_si.c
@@ -21,7 +21,6 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
@@ -37,7 +36,7 @@ main (int argc, char *argv[])
mpfr_init2(x, 100);
- srandom(time(NULL));
+ SEED_RAND (getpid ());
N = (argc==1) ? 1000000 : atoi(argv[1]);
diff --git a/tests/tset_str.c b/tests/tset_str.c
index ce052e6b8..f0dd388c0 100644
--- a/tests/tset_str.c
+++ b/tests/tset_str.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set_str.
-Copyright 1999, 2001 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -22,7 +22,6 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
@@ -48,20 +47,20 @@ main (int argc, char *argv[])
return 0;
}
- srandom (time (NULL));
+ SEED_RAND (getpid ());
nc = (argc > 1) ? atoi(argv[1]) : 53;
if (nc < 100)
nc = 100;
- bd = random() & 8;
+ bd = LONG_RAND() & 8;
str2 = str = (char *) malloc (nc * sizeof(char));
if (bd)
{
for(k = 1; k <= bd; k++)
- *(str2++) = (random() & 1) + '0';
+ *(str2++) = (LONG_RAND() & 1) + '0';
}
else
*(str2++) = '0';
@@ -69,10 +68,10 @@ main (int argc, char *argv[])
*(str2++) = '.';
for (k = 1; k < nc - 17 - bd; k++)
- *(str2++) = '0' + (random() & 1);
+ *(str2++) = '0' + (LONG_RAND() & 1);
*(str2++) = 'e';
- sprintf (str2, "%d", (int) random() - (1 << 30));
+ sprintf (str2, "%d", (int) LONG_RAND() - (1 << 30));
mpfr_init2 (x, nc + 10);
mpfr_set_str_raw (x, str);
@@ -131,8 +130,8 @@ main (int argc, char *argv[])
for (i=0;i<100000;i++)
{
mpfr_random (x);
- k = rand() % 4;
- logbase = (rand() % 5) + 1;
+ k = LONG_RAND() % 4;
+ logbase = (LONG_RAND() % 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 214d3bb70..05231102f 100644
--- a/tests/tset_z.c
+++ b/tests/tset_z.c
@@ -24,6 +24,7 @@ MA 02111-1307, USA. */
#include <unistd.h>
#include "gmp.h"
#include "mpfr.h"
+#include "mpfr-test.h"
void check _PROTO((long, unsigned char));
void check_large _PROTO((void));
@@ -66,10 +67,10 @@ main (int argc, char *argv[])
long j;
check_large();
- srand(getpid());
+ SEED_RAND (getpid ());
check(0, 0);
for (j=0; j<1000000; j++)
- check(lrand48(), rand()%4);
+ check(LONG_RAND(), LONG_RAND()%4);
return 0;
}
diff --git a/tests/tsqrt.c b/tests/tsqrt.c
index 7420ca556..ef1d849ad 100644
--- a/tests/tsqrt.c
+++ b/tests/tsqrt.c
@@ -247,7 +247,7 @@ check_inexact (mp_prec_t p)
mpfr_init2 (y, p);
mpfr_init2 (z, 2*p);
mpfr_random (x);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
inexact = mpfr_sqrt (y, x, rnd);
if (mpfr_mul (z, y, y, rnd)) /* exact since prec(z) = 2*prec(y) */
{
@@ -289,11 +289,11 @@ main (void)
set_fpc_csr(exp.fc_word);
#endif
- srand(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<100000;i++) {
a = drand();
if (a < 0.0) a = -a; /* ensures a is positive */
- check(a, rand() % 4);
+ check(a, LONG_RAND() % 4);
}
#endif
for (p=2; p<200; p++)
diff --git a/tests/tsqrt_ui.c b/tests/tsqrt_ui.c
index 010fa089a..c14ef2fa7 100644
--- a/tests/tsqrt_ui.c
+++ b/tests/tsqrt_ui.c
@@ -68,11 +68,11 @@ main (void)
set_fpc_csr(exp.fc_word);
#endif
- srand(getpid());
+ SEED_RAND (getpid ());
for (i=0;i<1000000;i++) {
- a = lrand48();
+ a = LONG_RAND();
/* machine arithmetic must agree if a <= 2.0^53 */
- if (1.0*a < 9007199254872064.0) check(a, rand() % 4, -1.0);
+ if (1.0*a < 9007199254872064.0) check(a, LONG_RAND() % 4, -1.0);
}
#endif
check(0, GMP_RNDN, 0.0);
diff --git a/tests/tsub.c b/tests/tsub.c
index 8dede879f..e5767f48c 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -306,7 +306,7 @@ check_two_sum (mp_prec_t p)
mpfr_random (y);
if (mpfr_cmp_abs (x, y) < 0)
mpfr_swap (x, y);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
rnd = GMP_RNDN;
inexact = mpfr_sub (u, x, y, GMP_RNDN);
mpfr_sub (v, u, x, GMP_RNDN);
@@ -363,7 +363,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 = rand () % 4;
+ rnd = LONG_RAND () % 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 3e18ae101..447f58302 100644
--- a/tests/tsub_ui.c
+++ b/tests/tsub_ui.c
@@ -25,9 +25,7 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "mpfr.h"
#include "mpfr-impl.h"
-#ifdef __mips
-#include <sys/fpu.h>
-#endif
+#include "mpfr-test.h"
void check_two_sum _PROTO ((mp_prec_t));
void check3 _PROTO ((double, unsigned long, mp_rnd_t, double));
@@ -82,11 +80,11 @@ check_two_sum (mp_prec_t p)
mpfr_init2 (w, p);
do
{
- x = lrand48 ();
+ x = LONG_RAND ();
}
while (x < 1);
mpfr_random (y);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
rnd = GMP_RNDN;
inexact = mpfr_sub_ui (u, y, x, GMP_RNDN);
mpfr_add_ui (v, u, x, GMP_RNDN);
@@ -127,15 +125,15 @@ main (int argc, char *argv[])
#ifdef TEST
double x; unsigned long y, N; int i,rnd_mode,rnd;
- srand(getpid());
+ SEED_RAND (getpid ());
N = (argc<2) ? 1000000 : atoi(argv[1]);
rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
for (i=0;i<1000000;i++) {
- x = drand48();
- y = lrand48();
+ x = drand();
+ y = LONG_RAND();
if (ABS(x)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check(x, y, rnd);
}
}
diff --git a/tests/tui_div.c b/tests/tui_div.c
index 54e557e88..27bd1cdc9 100644
--- a/tests/tui_div.c
+++ b/tests/tui_div.c
@@ -73,7 +73,7 @@ check_inexact (void)
{
mpfr_set_prec (x, px);
mpfr_random (x);
- u = lrand48 ();
+ u = LONG_RAND ();
for (py=2; py<300; py++)
{
mpfr_set_prec (y, py);
@@ -121,15 +121,15 @@ main (int argc, char *argv[])
set_fpc_csr(exp.fc_word);
#endif
- srand48(getpid());
+ SEED_RAND(getpid());
N = (argc<2) ? 1000000 : atoi(argv[1]);
rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
for (i=0;i<1000000;i++) {
x = drand();
- y = lrand48();
+ y = LONG_RAND();
if (ABS(x)>4e-286) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check(y, x, rnd, 0.0);
}
}
diff --git a/tests/tui_sub.c b/tests/tui_sub.c
index 89b9bba6f..495bbf338 100644
--- a/tests/tui_sub.c
+++ b/tests/tui_sub.c
@@ -168,11 +168,11 @@ check_two_sum (mp_prec_t p)
mpfr_init2 (w, p);
do
{
- x = lrand48 ();
+ x = LONG_RAND ();
}
while (x < 1);
mpfr_random (y);
- rnd = rand() % 4;
+ rnd = LONG_RAND() % 4;
rnd = GMP_RNDN;
inexact = mpfr_ui_sub (u, x, y, GMP_RNDN);
mpfr_sub_ui (v, u, x, GMP_RNDN);
@@ -215,15 +215,15 @@ main (int argc, char *argv[])
set_fpc_csr(exp.fc_word);
#endif
- srand48(getpid());
+ SEED_RAND (getpid());
N = (argc<2) ? 1000000 : atoi(argv[1]);
rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
for (i=0;i<1000000;i++) {
- x = drand();
- y = lrand48();
+ x = drand ();
+ y = LONG_RAND ();
if (ABS(x)>2.2e-307) {
/* avoid denormalized numbers and overflows */
- rnd = (rnd_mode==-1) ? lrand48()%4 : rnd_mode;
+ rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
check(y, x, rnd, 0.0);
}
}