summaryrefslogtreecommitdiff
path: root/tests/tcmp2.c
diff options
context:
space:
mode:
authorhanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4>1999-06-09 18:03:33 +0000
committerhanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4>1999-06-09 18:03:33 +0000
commit0cf5fc5ea4b5ed46b454d3bf3adc620d9fff2d32 (patch)
tree62d12a119f5dfc15abe2f6d298617e174a0a06af /tests/tcmp2.c
parent8d21dd7188076894a6f65e510797c8c6928e474f (diff)
downloadmpfr-0cf5fc5ea4b5ed46b454d3bf3adc620d9fff2d32.tar.gz
Initial revision
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tcmp2.c')
-rw-r--r--tests/tcmp2.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/tcmp2.c b/tests/tcmp2.c
new file mode 100644
index 000000000..c4c080b97
--- /dev/null
+++ b/tests/tcmp2.c
@@ -0,0 +1,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);
+ }
+ }
+}
+