summaryrefslogtreecommitdiffstats
path: root/contrib/libgmp/mpf/tests
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libgmp/mpf/tests')
-rw-r--r--contrib/libgmp/mpf/tests/Makefile.in75
-rw-r--r--contrib/libgmp/mpf/tests/configure.in11
-rw-r--r--contrib/libgmp/mpf/tests/ref.c203
-rw-r--r--contrib/libgmp/mpf/tests/reuse.c186
-rw-r--r--contrib/libgmp/mpf/tests/t-add.c117
-rw-r--r--contrib/libgmp/mpf/tests/t-conv.c120
-rw-r--r--contrib/libgmp/mpf/tests/t-dm2exp.c101
-rw-r--r--contrib/libgmp/mpf/tests/t-muldiv.c161
-rw-r--r--contrib/libgmp/mpf/tests/t-sqrt.c103
-rw-r--r--contrib/libgmp/mpf/tests/t-sub.c122
10 files changed, 1199 insertions, 0 deletions
diff --git a/contrib/libgmp/mpf/tests/Makefile.in b/contrib/libgmp/mpf/tests/Makefile.in
new file mode 100644
index 0000000..e108b9e
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/Makefile.in
@@ -0,0 +1,75 @@
+# Makefile for mpf/tests for GNU MP
+
+srcdir = .
+
+CC = gcc
+
+TEST_LIBS = ../../libgmp.a
+INCLUDES = -I../../mpn -I$(srcdir)/../..
+CFLAGS = -g -O
+
+.c.o:
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(XCFLAGS) $<
+
+TEST_SRCS = t-add.c t-sub.c t-conv.c t-sqrt.c t-muldiv.c t-dm2exp.c t-reuse.c ref.c
+TEST_OBJS = t-add.o t-sub.o t-conv.o t-sqrt.o t-muldiv.o t-dm2exp.c reuse.o
+TESTS = t-add t-sub t-conv t-sqrt t-muldiv t-dm2exp reuse
+
+check: Makefile st-add st-sub st-conv st-sqrt st-muldiv st-dm2exp st-reuse
+ @echo "The tests passed."
+
+st-add: t-add
+ ./t-add
+ touch $@
+st-sub: t-sub
+ ./t-sub
+ touch $@
+st-conv: t-conv
+ ./t-conv
+ touch $@
+st-sqrt: t-sqrt
+ ./t-sqrt
+ touch $@
+st-muldiv: t-muldiv
+ ./t-muldiv
+ touch $@
+st-dm2exp: t-dm2exp
+ ./t-dm2exp
+ touch $@
+st-reuse: reuse
+ ./reuse
+ touch $@
+
+H = $(srcdir)/../../gmp.h $(srcdir)/../../gmp-impl.h \
+ $(srcdir)/../../urandom.h ../../mpn/gmp-mparam.h
+
+t-add: t-add.o ref.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o ref.o $(TEST_LIBS) $(CFLAGS)
+t-sub: t-sub.o ref.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o ref.o $(TEST_LIBS) $(CFLAGS)
+t-conv: t-conv.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
+t-sqrt: t-sqrt.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
+t-muldiv: t-muldiv.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
+t-dm2exp: t-dm2exp.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
+reuse: reuse.o $(TEST_LIBS)
+ $(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
+
+t-add.o: $(srcdir)/t-add.c
+t-sub.o: $(srcdir)/t-sub.c
+t-conv.o: $(srcdir)/t-conv.c
+t-sqrt.o: $(srcdir)/t-sqrt.c
+t-muldiv.o: $(srcdir)/t-muldiv.c
+t-dm2exp.o: $(srcdir)/t-dm2exp.c
+reuse.o: $(srcdir)/reuse.c
+
+clean mostlyclean:
+ rm -f *.o st-* $(TESTS)
+distclean maintainer-clean: clean
+ rm -f Makefile config.status
+
+Makefile: $(srcdir)/Makefile.in
+ $(SHELL) ./config.status
diff --git a/contrib/libgmp/mpf/tests/configure.in b/contrib/libgmp/mpf/tests/configure.in
new file mode 100644
index 0000000..319219c
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/configure.in
@@ -0,0 +1,11 @@
+# This file is a shell script that supplies the information necessary
+# to tailor a template configure script into the configure script
+# appropriate for this directory. For more information, check any
+# existing configure script.
+
+srctrigger=t-add.c
+srcname="gmp/mpf/tests"
+
+# per-host:
+
+# per-target:
diff --git a/contrib/libgmp/mpf/tests/ref.c b/contrib/libgmp/mpf/tests/ref.c
new file mode 100644
index 0000000..b2c3e6c
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/ref.c
@@ -0,0 +1,203 @@
+/* Reference floating point routines.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
+#if __STDC__
+void ref_mpf_add (mpf_t, const mpf_t, const mpf_t);
+void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t);
+#else
+void ref_mpf_add ();
+void ref_mpf_sub ();
+#endif
+
+void
+#if __STDC__
+ref_mpf_add (mpf_t w, const mpf_t u, const mpf_t v)
+#else
+ref_mpf_add (w, u, v)
+ mpf_t w;
+ const mpf_t u;
+ const mpf_t v;
+#endif
+{
+ mp_size_t hi, lo, size;
+ mp_ptr ut, vt, wt;
+ int neg;
+ mp_exp_t exp;
+ mp_limb_t cy;
+ TMP_DECL (mark);
+
+ TMP_MARK (mark);
+
+ if (SIZ (u) == 0)
+ {
+ size = ABSIZ (v);
+ wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
+ MPN_COPY (wt, PTR (v), size);
+ exp = EXP (v);
+ neg = SIZ (v) < 0;
+ goto done;
+ }
+ if (SIZ (v) == 0)
+ {
+ size = ABSIZ (u);
+ wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
+ MPN_COPY (wt, PTR (u), size);
+ exp = EXP (u);
+ neg = SIZ (u) < 0;
+ goto done;
+ }
+ if ((SIZ (u) ^ SIZ (v)) < 0)
+ {
+ mpf_t tmp;
+ SIZ (tmp) = -SIZ (v);
+ EXP (tmp) = EXP (v);
+ PTR (tmp) = PTR (v);
+ ref_mpf_sub (w, u, tmp);
+ return;
+ }
+ neg = SIZ (u) < 0;
+
+ /* Compute the significance of the hi and lo end of the result. */
+ hi = MAX (EXP (u), EXP (v));
+ lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
+ size = hi - lo;
+ ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ MPN_ZERO (ut, size);
+ MPN_ZERO (vt, size);
+ {int off;
+ off = size + (EXP (u) - hi) - ABSIZ (u);
+ MPN_COPY (ut + off, PTR (u), ABSIZ (u));
+ off = size + (EXP (v) - hi) - ABSIZ (v);
+ MPN_COPY (vt + off, PTR (v), ABSIZ (v));
+ }
+
+ cy = mpn_add_n (wt, ut, vt, size);
+ wt[size] = cy;
+ size += cy;
+ exp = hi + cy;
+
+done:
+ if (size > PREC (w))
+ {
+ wt += size - PREC (w);
+ size = PREC (w);
+ }
+ MPN_COPY (PTR (w), wt, size);
+ SIZ (w) = neg == 0 ? size : -size;
+ EXP (w) = exp;
+ TMP_FREE (mark);
+}
+
+void
+#if __STDC__
+ref_mpf_sub (mpf_t w, const mpf_t u, const mpf_t v)
+#else
+ref_mpf_sub (w, u, v)
+ mpf_t w;
+ const mpf_t u;
+ const mpf_t v;
+#endif
+{
+ mp_size_t hi, lo, size;
+ mp_ptr ut, vt, wt;
+ int neg;
+ mp_exp_t exp;
+ TMP_DECL (mark);
+
+ TMP_MARK (mark);
+
+ if (SIZ (u) == 0)
+ {
+ size = ABSIZ (v);
+ wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
+ MPN_COPY (wt, PTR (v), size);
+ exp = EXP (v);
+ neg = SIZ (v) > 0;
+ goto done;
+ }
+ if (SIZ (v) == 0)
+ {
+ size = ABSIZ (u);
+ wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
+ MPN_COPY (wt, PTR (u), size);
+ exp = EXP (u);
+ neg = SIZ (u) < 0;
+ goto done;
+ }
+ if ((SIZ (u) ^ SIZ (v)) < 0)
+ {
+ mpf_t tmp;
+ SIZ (tmp) = -SIZ (v);
+ EXP (tmp) = EXP (v);
+ PTR (tmp) = PTR (v);
+ ref_mpf_add (w, u, tmp);
+ if (SIZ (u) < 0)
+ mpf_neg (w, w);
+ return;
+ }
+ neg = SIZ (u) < 0;
+
+ /* Compute the significance of the hi and lo end of the result. */
+ hi = MAX (EXP (u), EXP (v));
+ lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
+ size = hi - lo;
+ ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
+ MPN_ZERO (ut, size);
+ MPN_ZERO (vt, size);
+ {int off;
+ off = size + (EXP (u) - hi) - ABSIZ (u);
+ MPN_COPY (ut + off, PTR (u), ABSIZ (u));
+ off = size + (EXP (v) - hi) - ABSIZ (v);
+ MPN_COPY (vt + off, PTR (v), ABSIZ (v));
+ }
+
+ if (mpn_cmp (ut, vt, size) >= 0)
+ mpn_sub_n (wt, ut, vt, size);
+ else
+ {
+ mpn_sub_n (wt, vt, ut, size);
+ neg ^= 1;
+ }
+ exp = hi;
+ while (size != 0 && wt[size - 1] == 0)
+ {
+ size--;
+ exp--;
+ }
+
+done:
+ if (size > PREC (w))
+ {
+ wt += size - PREC (w);
+ size = PREC (w);
+ }
+ MPN_COPY (PTR (w), wt, size);
+ SIZ (w) = neg == 0 ? size : -size;
+ EXP (w) = exp;
+ TMP_FREE (mark);
+}
diff --git a/contrib/libgmp/mpf/tests/reuse.c b/contrib/libgmp/mpf/tests/reuse.c
new file mode 100644
index 0000000..6829cc4
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/reuse.c
@@ -0,0 +1,186 @@
+/* Test that routines allow reusing a source variable as destination. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+#ifndef EXPO
+#define EXPO 32
+#endif
+
+#if __STDC__
+typedef void (*dss_func) (mpf_ptr, mpf_srcptr, mpf_srcptr);
+#else
+typedef void (*dss_func) ();
+#endif
+
+dss_func dss_funcs[] =
+{
+ mpf_div, mpf_add, mpf_mul, mpf_sub,
+};
+
+char *dss_func_names[] =
+{
+ "mpf_div", "mpf_add", "mpf_mul", "mpf_sub",
+};
+
+#if __STDC__
+typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int);
+#else
+typedef void (*dsi_func) ();
+#endif
+
+dsi_func dsi_funcs[] =
+{
+ mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
+};
+
+char *dsi_func_names[] =
+{
+ "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
+};
+
+#if __STDC__
+typedef void (*dis_func) (mpf_ptr, unsigned long int, mpf_srcptr);
+#else
+typedef void (*dis_func) ();
+#endif
+
+dis_func dis_funcs[] =
+{
+ mpf_ui_div, mpf_ui_sub,
+};
+
+char *dis_func_names[] =
+{
+ "mpf_ui_div", "mpf_ui_sub",
+};
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int i;
+ int pass, reps = 100000;
+ mpf_t in1, in2, out1;
+ unsigned long int in1i, in2i;
+ mpf_t res1, res2, res3;
+ mp_size_t bprec = 100;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init (in1);
+ mpf_init (in2);
+ mpf_init (out1);
+ mpf_init (res1);
+ mpf_init (res2);
+ mpf_init (res3);
+
+ for (pass = 1; pass <= reps; pass++)
+ {
+ mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO);
+ mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO);
+
+ for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
+ {
+ /* Don't divide by 0. */
+ if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
+ continue;
+
+ (dss_funcs[i]) (res1, in1, in2);
+
+ mpf_set (out1, in1);
+ (dss_funcs[i]) (out1, out1, in2);
+ mpf_set (res2, out1);
+
+ mpf_set (out1, in2);
+ (dss_funcs[i]) (out1, in1, out1);
+ mpf_set (res3, out1);
+
+ if (mpf_cmp (res1, res2) != 0)
+ dump_abort (dss_func_names[i], res1, res2);
+ if (mpf_cmp (res1, res3) != 0)
+ dump_abort (dss_func_names[i], res1, res3);
+ }
+
+ in2i = urandom ();
+ for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
+ {
+ /* Don't divide by 0. */
+ if (i == 0 && in2i == 0)
+ continue;
+
+ (dsi_funcs[i]) (res1, in1, in2i);
+
+ mpf_set (out1, in1);
+ (dsi_funcs[i]) (out1, out1, in2i);
+ mpf_set (res2, out1);
+
+ if (mpf_cmp (res1, res2) != 0)
+ dump_abort (dsi_func_names[i], res1, res2);
+ }
+
+ in1i = urandom ();
+ for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
+ {
+ /* Don't divide by 0. */
+ if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
+ continue;
+
+ (dis_funcs[i]) (res1, in1i, in2);
+
+ mpf_set (out1, in2);
+ (dis_funcs[i]) (out1, in1i, in2);
+ mpf_set (res2, out1);
+
+ if (mpf_cmp (res1, res2) != 0)
+ dump_abort (dis_func_names[i], res1, res2);
+ }
+
+ }
+
+ exit (0);
+}
+
+dump_abort (name, res1, res2)
+ char *name;
+ mpf_t res1, res2;
+{
+ printf ("failure in %s:", name);
+ oo (res1);
+ oo (res2);
+ abort ();
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
+
+#if 0
+void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
+void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
+
+void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
+void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
+void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
+#endif
diff --git a/contrib/libgmp/mpf/tests/t-add.c b/contrib/libgmp/mpf/tests/t-add.c
new file mode 100644
index 0000000..6f985bb
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-add.c
@@ -0,0 +1,117 @@
+/* Test mpf_add.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+#if __STDC__
+void ref_mpf_add (mpf_t, const mpf_t, const mpf_t);
+void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t);
+#else
+void ref_mpf_add ();
+void ref_mpf_sub ();
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ mp_size_t size;
+ mp_exp_t exp;
+ int reps = 100000;
+ int i;
+ mpf_t u, v, w, wref;
+ mp_size_t bprec = 100;
+ mpf_t rerr, max_rerr, limit_rerr;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, bprec);
+#if VERBOSE
+ mpf_dump (limit_rerr);
+#endif
+ mpf_init (rerr);
+ mpf_init_set_ui (max_rerr, 0);
+
+ mpf_init (u);
+ mpf_init (v);
+ mpf_init (w);
+ mpf_init (wref);
+ for (i = 0; i < reps; i++)
+ {
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (u, size, exp);
+
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (v, size, exp);
+
+ mpf_add (w, u, v);
+ ref_mpf_add (wref, u, v);
+
+ mpf_reldiff (rerr, w, wref);
+ if (mpf_cmp (rerr, max_rerr) > 0)
+ {
+ mpf_set (max_rerr, rerr);
+#if VERBOSE
+ mpf_dump (max_rerr);
+#endif
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf ("wref = "); mpf_dump (wref);
+ printf (" w = "); mpf_dump (w);
+ abort ();
+ }
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
diff --git a/contrib/libgmp/mpf/tests/t-conv.c b/contrib/libgmp/mpf/tests/t-conv.c
new file mode 100644
index 0000000..00d461d
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-conv.c
@@ -0,0 +1,120 @@
+/* Test mpf_get_str and mpf_set_str.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 10
+#endif
+
+#ifndef EXPO
+#define EXPO 20
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ mpf_t x, y;
+ int reps = 20000;
+ int i;
+ mp_size_t bprec = 100;
+ mpf_t d, rerr, max_rerr, limit_rerr;
+ char *str;
+ long bexp;
+ long size, exp;
+ int base;
+ char buf[SIZE * BITS_PER_MP_LIMB + 5];
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, bprec);
+#if VERBOSE
+ mpf_dump (limit_rerr);
+#endif
+ mpf_init (rerr);
+ mpf_init_set_ui (max_rerr, 0);
+
+ mpf_init (x);
+ mpf_init (y);
+ mpf_init (d);
+
+ for (i = 0; i < reps; i++)
+ {
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % EXPO;
+ mpf_random2 (x, size, exp);
+
+ base = urandom () % 35 + 2;
+
+ str = mpf_get_str (0, &bexp, base, 0, x);
+
+ if (str[0] == '-')
+ sprintf (buf, "-0.%s@%ld", str + 1, bexp);
+ else
+ sprintf (buf, "0.%s@%ld", str, bexp);
+
+ mpf_set_str (y, buf, -base);
+ free (str);
+
+ mpf_reldiff (rerr, x, y);
+ if (mpf_cmp (rerr, max_rerr) > 0)
+ {
+ mpf_set (max_rerr, rerr);
+#if VERBOSE
+ mpf_dump (max_rerr);
+#endif
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR after %d tests\n", i);
+ printf ("base = %d\n", base);
+ printf (" x = "); mpf_dump (x);
+ printf (" y = "); mpf_dump (y);
+ abort ();
+ }
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ int i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
diff --git a/contrib/libgmp/mpf/tests/t-dm2exp.c b/contrib/libgmp/mpf/tests/t-dm2exp.c
new file mode 100644
index 0000000..a8c4e8f
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-dm2exp.c
@@ -0,0 +1,101 @@
+/* Test mpf_div, mpf_div_2exp, mpf_mul_2exp.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int reps = 500000;
+ int i;
+ mpf_t u, v, w1, w2;
+ mp_size_t bprec = 100;
+ mpf_t rerr, limit_rerr;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init (rerr);
+ mpf_init (limit_rerr);
+
+ mpf_init (u);
+ mpf_init (v);
+ mpf_init (w1);
+ mpf_init (w2);
+
+ for (i = 0; i < reps; i++)
+ {
+ mp_size_t res_prec;
+ unsigned long int pow2;
+
+ res_prec = urandom () % (bprec + 100);
+ mpf_set_prec (w1, res_prec);
+ mpf_set_prec (w2, res_prec);
+
+ mpf_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
+
+ pow2 = urandom () % 0x10000;
+ mpf_set_ui (v, 1);
+ mpf_mul_2exp (v, v, pow2);
+
+ mpf_div_2exp (w1, u, pow2);
+ mpf_div (w2, u, v);
+ mpf_reldiff (rerr, w1, w2);
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf (" w1 = "); mpf_dump (w1);
+ printf (" w2 = "); mpf_dump (w2);
+ abort ();
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
diff --git a/contrib/libgmp/mpf/tests/t-muldiv.c b/contrib/libgmp/mpf/tests/t-muldiv.c
new file mode 100644
index 0000000..d1721e8
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-muldiv.c
@@ -0,0 +1,161 @@
+/* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ mp_size_t size;
+ mp_exp_t exp;
+ int reps = 100000;
+ int i;
+ mpf_t u, v, w, x;
+ mp_size_t bprec = 100;
+ mpf_t rerr, limit_rerr;
+ mp_limb_t ulimb, vlimb;
+ int single_flag;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init (rerr);
+ mpf_init (limit_rerr);
+
+ mpf_init (u);
+ mpf_init (v);
+ mpf_init (w);
+ mpf_init (x);
+
+ for (i = 0; i < reps; i++)
+ {
+ mp_size_t res_prec;
+
+ res_prec = urandom () % (bprec + 100);
+ mpf_set_prec (w, res_prec);
+ mpf_set_prec (x, res_prec);
+
+ mpf_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
+
+ single_flag = 0;
+
+ if ((urandom () & 1) != 0)
+ {
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (u, size, exp);
+ }
+ else
+ {
+ ulimb = urandom ();
+ mpf_set_ui (u, ulimb);
+ single_flag = 1;
+ }
+
+ if ((urandom () & 1) != 0)
+ {
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (v, size, exp);
+ }
+ else
+ {
+ vlimb = urandom ();
+ mpf_set_ui (v, vlimb);
+ single_flag = 2;
+ }
+
+ if (mpf_sgn (v) == 0)
+ continue;
+
+ mpf_div (w, u, v);
+ mpf_mul (x, w, v);
+ mpf_reldiff (rerr, u, x);
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf (" x = "); mpf_dump (x);
+ printf (" w = "); mpf_dump (w);
+ abort ();
+ }
+
+ if (single_flag == 2)
+ {
+ mpf_div_ui (x, u, vlimb);
+ mpf_reldiff (rerr, w, x);
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf (" x = "); mpf_dump (x);
+ printf (" w = "); mpf_dump (w);
+ abort ();
+ }
+ }
+
+ if (single_flag == 1)
+ {
+ mpf_ui_div (x, ulimb, v);
+ mpf_reldiff (rerr, w, x);
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf (" x = "); mpf_dump (x);
+ printf (" w = "); mpf_dump (w);
+ abort ();
+ }
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
diff --git a/contrib/libgmp/mpf/tests/t-sqrt.c b/contrib/libgmp/mpf/tests/t-sqrt.c
new file mode 100644
index 0000000..5c72ab5
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-sqrt.c
@@ -0,0 +1,103 @@
+/* Test mpf_sqrt, mpf_mul.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ mp_size_t size;
+ mp_exp_t exp;
+ int reps = 100000;
+ int i;
+ mpf_t x, y, y2;
+ mp_size_t bprec = 100;
+ mpf_t rerr, max_rerr, limit_rerr;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, bprec);
+#if VERBOSE
+ mpf_dump (limit_rerr);
+#endif
+ mpf_init (rerr);
+ mpf_init_set_ui (max_rerr, 0);
+
+ mpf_init (x);
+ mpf_init (y);
+ mpf_init (y2);
+ for (i = 0; i < reps; i++)
+ {
+ size = urandom () % SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (x, size, exp);
+
+ mpf_sqrt (y, x);
+ mpf_mul (y2, y, y);
+
+ mpf_reldiff (rerr, x, y2);
+ if (mpf_cmp (rerr, max_rerr) > 0)
+ {
+ mpf_set (max_rerr, rerr);
+#if VERBOSE
+ mpf_dump (max_rerr);
+#endif
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR after %d tests\n", i);
+ printf (" x = "); mpf_dump (x);
+ printf (" y = "); mpf_dump (y);
+ printf (" y2 = "); mpf_dump (y2);
+ abort ();
+ }
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
diff --git a/contrib/libgmp/mpf/tests/t-sub.c b/contrib/libgmp/mpf/tests/t-sub.c
new file mode 100644
index 0000000..6918866
--- /dev/null
+++ b/contrib/libgmp/mpf/tests/t-sub.c
@@ -0,0 +1,122 @@
+/* Test mpf_sub.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "urandom.h"
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+#if __STDC__
+void ref_mpf_add (mpf_t, const mpf_t, const mpf_t);
+void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t);
+#else
+void ref_mpf_add ();
+void ref_mpf_sub ();
+#endif
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ mp_size_t size;
+ mp_exp_t exp;
+ int reps = 500000;
+ int i;
+ mpf_t u, v, w, wref;
+ mp_size_t bprec = 100;
+ mpf_t rerr, max_rerr, limit_rerr;
+
+ if (argc > 1)
+ {
+ reps = strtol (argv[1], 0, 0);
+ if (argc > 2)
+ bprec = strtol (argv[2], 0, 0);
+ }
+
+ mpf_set_default_prec (bprec);
+
+ mpf_init_set_ui (limit_rerr, 1);
+ mpf_div_2exp (limit_rerr, limit_rerr, bprec);
+#if VERBOSE
+ mpf_dump (limit_rerr);
+#endif
+ mpf_init (rerr);
+ mpf_init_set_ui (max_rerr, 0);
+
+ mpf_init (u);
+ mpf_init (v);
+ mpf_init (w);
+ mpf_init (wref);
+ for (i = 0; i < reps; i++)
+ {
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (u, size, exp);
+
+ size = urandom () % (2 * SIZE) - SIZE;
+ exp = urandom () % SIZE;
+ mpf_random2 (v, size, exp);
+
+ if ((urandom () & 1) != 0)
+ mpf_add_ui (u, v, 1);
+ else if ((urandom () & 1) != 0)
+ mpf_sub_ui (u, v, 1);
+
+ mpf_sub (w, u, v);
+ ref_mpf_sub (wref, u, v);
+
+ mpf_reldiff (rerr, w, wref);
+ if (mpf_cmp (rerr, max_rerr) > 0)
+ {
+ mpf_set (max_rerr, rerr);
+#if VERBOSE
+ mpf_dump (max_rerr);
+#endif
+ if (mpf_cmp (rerr, limit_rerr) > 0)
+ {
+ printf ("ERROR after %d tests\n", i);
+ printf (" u = "); mpf_dump (u);
+ printf (" v = "); mpf_dump (v);
+ printf ("wref = "); mpf_dump (wref);
+ printf (" w = "); mpf_dump (w);
+ abort ();
+ }
+ }
+ }
+
+ exit (0);
+}
+
+oo (x)
+ mpf_t x;
+{
+ mp_size_t i;
+ printf (" exp = %ld\n", x->_mp_exp);
+ printf ("size = %d\n", x->_mp_size);
+ for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
+ printf ("%08lX ", x->_mp_d[i]);
+ printf ("\n");
+ mpf_dump (x);
+}
OpenPOWER on IntegriCloud