1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "gmp.h"
#include "longlong.h"
#include "mpfr.h"
double drand()
{
double d; long int *i;
i = (long int*) &d;
i[0] = lrand48();
i[1] = lrand48();
return d;
}
void tcmp2(x, y, i) double x, y; int i;
{
mpfr_t xx,yy; int j;
if (i==-1) i = (int) floor(log(x)/log(2.0)) - (int) floor(log(x-y)/log(2.0));
mpfr_init2(xx, 53); mpfr_init2(yy, 53);
mpfr_set_d(xx, x, 0);
mpfr_set_d(yy, y, 0);
if ((j=mpfr_cmp2(xx, yy)) != i) {
printf("Error in mpfr_cmp2: x=%1.16e y=%1.16e mpfr_cmp(x,y)=%d instead of %d\n",x,y,j,i);
exit(1);
}
mpfr_clear(xx); mpfr_clear(yy);
}
void main()
{
int i,j; double x=1.0, y, z;
tcmp2(1.06022698059744327881e+71, 1.05824655795525779205e+71, -1);
tcmp2(1.0, 1.0, 53);
for (i=0;i<54;i++) {
tcmp2(1.0, 1.0-x, i);
x /= 2.0;
}
for (j=0;j<1000000;j++) {
x = drand(); if (x<0) x = -x;
y = drand(); if (y<0) y = -y;
if (!isnan(x) && !isnan(y)) {
if (x<y) { z=x; x=y; y=z; }
tcmp2(x, y, -1);
}
}
}
|