diff options
Diffstat (limited to 'mpfr-impl.h')
-rw-r--r-- | mpfr-impl.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/mpfr-impl.h b/mpfr-impl.h new file mode 100644 index 000000000..5606ff70b --- /dev/null +++ b/mpfr-impl.h @@ -0,0 +1,23 @@ +/* generate a random double using the whole range of possible values, + including denormalized numbers, NaN, infinities, ... */ +double drand() +{ + double d; int *i; + + i = (int*) &d; + i[0] = lrand48(); + i[1] = lrand48(); + if (lrand48()%2) d=-d; /* generates negative numbers */ + return d; +} + +/* returns the number of ulp's between a and b */ +int ulp(a,b) double a,b; +{ + double eps=1.1102230246251565404e-16; /* 2^(-53) */ + b = (a-b)/a; + if (b>0) + return (int) floor(b/eps); + else + return (int) ceil(b/eps); +} |