summaryrefslogtreecommitdiff
path: root/tests/tdiv_ui.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>1999-06-25 11:21:30 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>1999-06-25 11:21:30 +0000
commit74427bb76f32595555f81e5157d557b99f120e57 (patch)
treecceb32c731b13768499c8cf9c3ba66b7db31bb72 /tests/tdiv_ui.c
parent8963ca37ed20e5436b400041c709caf540a1cb0d (diff)
downloadmpfr-74427bb76f32595555f81e5157d557b99f120e57.tar.gz
test file for div_ui, initial revision
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@177 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tdiv_ui.c')
-rw-r--r--tests/tdiv_ui.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c
new file mode 100644
index 000000000..6232ea5e8
--- /dev/null
+++ b/tests/tdiv_ui.c
@@ -0,0 +1,62 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "gmp.h"
+#include "mpfr.h"
+#include "time.h"
+
+double drand()
+{
+ double d; long int *i;
+
+ i = (long 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) b = -b;
+ return (int) floor(b/eps);
+}
+
+check(double d, unsigned int u, unsigned char rnd)
+{
+ mpfr_t x, y; double e, f;
+
+ mpfr_init2(x, 53); mpfr_init2(y, 53);
+ mpfr_set_machine_rnd_mode(rnd);
+ e = d / u;
+ mpfr_set_d(x, d, rnd);
+ mpfr_div_ui(y, x, u, rnd);
+ f = mpfr_get_d(y);
+ if (f != e && (!isnan(f) || !isnan(e))) {
+ printf("mpfr_div_ui failed for x=%1.20e, u=%lu, rnd=%d\n",d,u,rnd);
+ printf("expected result is %1.20e, got %1.20e, dif=%d ulp\n",e,f,
+ ulp(e,f));
+ exit(1);
+ }
+ mpfr_clear(x);
+}
+
+int
+main(int argc, char **argv)
+{
+ int i; unsigned int u; double d;
+
+ srand(getpid());
+ check(1.0, 3, 0);
+ check(1.0, 3, 1);
+ check(1.0, 3, 2);
+ check(1.0, 3, 3);
+ check(1.0, 2116118, 0);
+ for (i=0;i<1000000;i++) {
+ do { u = lrand48(); } while (u==0);
+ do { d = drand(); } while (fabs(d/u)<2.2e-307);
+ check(d, u, rand() % 4);
+ }
+}