Annotation of OpenXM/src/kan96xx/gmp-2.0.2/mpf/tests/reuse.c, Revision 1.1
1.1 ! maekawa 1: /* Test that routines allow reusing a source variable as destination. */
! 2:
! 3: #include <stdio.h>
! 4: #include "gmp.h"
! 5: #include "gmp-impl.h"
! 6: #include "urandom.h"
! 7:
! 8: #ifndef SIZE
! 9: #define SIZE 16
! 10: #endif
! 11:
! 12: #ifndef EXPO
! 13: #define EXPO 32
! 14: #endif
! 15:
! 16: #if __STDC__
! 17: typedef void (*dss_func) (mpf_ptr, mpf_srcptr, mpf_srcptr);
! 18: #else
! 19: typedef void (*dss_func) ();
! 20: #endif
! 21:
! 22: dss_func dss_funcs[] =
! 23: {
! 24: mpf_div, mpf_add, mpf_mul, mpf_sub,
! 25: };
! 26:
! 27: char *dss_func_names[] =
! 28: {
! 29: "mpf_div", "mpf_add", "mpf_mul", "mpf_sub",
! 30: };
! 31:
! 32: #if __STDC__
! 33: typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int);
! 34: #else
! 35: typedef void (*dsi_func) ();
! 36: #endif
! 37:
! 38: dsi_func dsi_funcs[] =
! 39: {
! 40: mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
! 41: };
! 42:
! 43: char *dsi_func_names[] =
! 44: {
! 45: "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
! 46: };
! 47:
! 48: #if __STDC__
! 49: typedef void (*dis_func) (mpf_ptr, unsigned long int, mpf_srcptr);
! 50: #else
! 51: typedef void (*dis_func) ();
! 52: #endif
! 53:
! 54: dis_func dis_funcs[] =
! 55: {
! 56: mpf_ui_div, mpf_ui_sub,
! 57: };
! 58:
! 59: char *dis_func_names[] =
! 60: {
! 61: "mpf_ui_div", "mpf_ui_sub",
! 62: };
! 63:
! 64: main (argc, argv)
! 65: int argc;
! 66: char **argv;
! 67: {
! 68: int i;
! 69: int pass, reps = 100000;
! 70: mpf_t in1, in2, out1;
! 71: unsigned long int in1i, in2i;
! 72: mpf_t res1, res2, res3;
! 73: mp_size_t bprec = 100;
! 74:
! 75: if (argc > 1)
! 76: {
! 77: reps = strtol (argv[1], 0, 0);
! 78: if (argc > 2)
! 79: bprec = strtol (argv[2], 0, 0);
! 80: }
! 81:
! 82: mpf_set_default_prec (bprec);
! 83:
! 84: mpf_init (in1);
! 85: mpf_init (in2);
! 86: mpf_init (out1);
! 87: mpf_init (res1);
! 88: mpf_init (res2);
! 89: mpf_init (res3);
! 90:
! 91: for (pass = 1; pass <= reps; pass++)
! 92: {
! 93: mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO);
! 94: mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO);
! 95:
! 96: for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
! 97: {
! 98: /* Don't divide by 0. */
! 99: if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
! 100: continue;
! 101:
! 102: (dss_funcs[i]) (res1, in1, in2);
! 103:
! 104: mpf_set (out1, in1);
! 105: (dss_funcs[i]) (out1, out1, in2);
! 106: mpf_set (res2, out1);
! 107:
! 108: mpf_set (out1, in2);
! 109: (dss_funcs[i]) (out1, in1, out1);
! 110: mpf_set (res3, out1);
! 111:
! 112: if (mpf_cmp (res1, res2) != 0)
! 113: dump_abort (dss_func_names[i], res1, res2);
! 114: if (mpf_cmp (res1, res3) != 0)
! 115: dump_abort (dss_func_names[i], res1, res3);
! 116: }
! 117:
! 118: in2i = urandom ();
! 119: for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
! 120: {
! 121: /* Don't divide by 0. */
! 122: if (i == 0 && in2i == 0)
! 123: continue;
! 124:
! 125: (dsi_funcs[i]) (res1, in1, in2i);
! 126:
! 127: mpf_set (out1, in1);
! 128: (dsi_funcs[i]) (out1, out1, in2i);
! 129: mpf_set (res2, out1);
! 130:
! 131: if (mpf_cmp (res1, res2) != 0)
! 132: dump_abort (dsi_func_names[i], res1, res2);
! 133: }
! 134:
! 135: in1i = urandom ();
! 136: for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
! 137: {
! 138: /* Don't divide by 0. */
! 139: if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
! 140: continue;
! 141:
! 142: (dis_funcs[i]) (res1, in1i, in2);
! 143:
! 144: mpf_set (out1, in2);
! 145: (dis_funcs[i]) (out1, in1i, in2);
! 146: mpf_set (res2, out1);
! 147:
! 148: if (mpf_cmp (res1, res2) != 0)
! 149: dump_abort (dis_func_names[i], res1, res2);
! 150: }
! 151:
! 152: }
! 153:
! 154: exit (0);
! 155: }
! 156:
! 157: dump_abort (name, res1, res2)
! 158: char *name;
! 159: mpf_t res1, res2;
! 160: {
! 161: printf ("failure in %s:", name);
! 162: oo (res1);
! 163: oo (res2);
! 164: abort ();
! 165: }
! 166:
! 167: oo (x)
! 168: mpf_t x;
! 169: {
! 170: mp_size_t i;
! 171: printf (" exp = %ld\n", x->_mp_exp);
! 172: printf ("size = %d\n", x->_mp_size);
! 173: for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
! 174: printf ("%08lX ", x->_mp_d[i]);
! 175: printf ("\n");
! 176: mpf_dump (x);
! 177: }
! 178:
! 179: #if 0
! 180: void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
! 181: void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
! 182:
! 183: void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
! 184: void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
! 185: void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
! 186: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>