diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-03-21 15:34:18 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-03-21 15:34:18 +0000 |
commit | 0df22d500aef3b11656722b40e21890ee1a5c531 (patch) | |
tree | 310ac3c9e4947239ba3813130858611607265061 /mpfr-test.h | |
parent | 0dec8d07551bd6f2a3708f717a1d74694833ca61 (diff) | |
download | mpfr-0df22d500aef3b11656722b40e21890ee1a5c531.tar.gz |
added macros LONG_RAND, DBL_RAND, SEED_RAND
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1761 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'mpfr-test.h')
-rw-r--r-- | mpfr-test.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/mpfr-test.h b/mpfr-test.h index 49ddb0fb4..98963e2f2 100644 --- a/mpfr-test.h +++ b/mpfr-test.h @@ -48,6 +48,12 @@ double Ulp _PROTO ((double)); #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define ABS(x) (((x)>0) ? (x) : -(x)) +/* generates a random long int, a random double, + and corresponding seed initializing */ +#define LONG_RAND lrand48 +#define DBL_RAND drand48 +#define SEED_RAND srand48 + /* generate a random double using the whole range of possible values, including denormalized numbers, NaN, infinities, ... */ double @@ -57,12 +63,16 @@ drand (void) i = (int*) &d; d = 1.0; - if (i[0]==0) expo=1; /* little endian, exponent in i[1] */ - else expo=0; - i[0] = lrand48(); - i[1] = lrand48(); - while (i[expo]>=2146435072) i[expo] = lrand48(); /* avoids NaNs */ - if (lrand48()%2 && !isnan(d)) d=-d; /* generates negative numbers */ + 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; } |