Annotation of OpenXM_contrib/gmp/tests/mpf/t-muldiv.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui.
2:
3: Copyright 1996, 2000, 2001 Free Software Foundation, Inc.
4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP Library is free software; you can redistribute it and/or modify
8: it under the terms of the GNU Lesser General Public License as published by
9: the Free Software Foundation; either version 2.1 of the License, or (at your
10: option) any later version.
11:
12: The GNU MP Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15: License for more details.
16:
17: You should have received a copy of the GNU Lesser General Public License
18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
22: #include <stdio.h>
23: #include <stdlib.h>
24:
25: #include "gmp.h"
26: #include "gmp-impl.h"
27: #include "tests.h"
28:
29: #ifndef SIZE
30: #define SIZE 16
31: #endif
32:
33: int
34: main (int argc, char **argv)
35: {
36: mp_size_t size;
37: mp_exp_t exp;
38: int reps = 100000;
39: int i;
40: mpf_t u, v, w, x;
41: mp_size_t bprec = SIZE * BITS_PER_MP_LIMB;
42: mpf_t rerr, limit_rerr;
43: mp_limb_t ulimb, vlimb;
44: int single_flag;
45:
46: tests_start ();
47:
48: if (argc > 1)
49: {
50: reps = strtol (argv[1], 0, 0);
51: if (argc > 2)
52: bprec = strtol (argv[2], 0, 0);
53: }
54:
55: mpf_set_default_prec (bprec);
56:
57: mpf_init (rerr);
58: mpf_init (limit_rerr);
59:
60: mpf_init (u);
61: mpf_init (v);
62: mpf_init (w);
63: mpf_init (x);
64:
65: for (i = 0; i < reps; i++)
66: {
67: mp_size_t res_prec;
68:
69: res_prec = urandom () % bprec + 1;
70: mpf_set_prec (w, res_prec);
71: mpf_set_prec (x, res_prec);
72:
73: mpf_set_ui (limit_rerr, 1);
74: mpf_div_2exp (limit_rerr, limit_rerr, res_prec - 1);
75:
76: single_flag = 0;
77:
78: if ((urandom () & 1) != 0)
79: {
80: size = urandom () % (2 * SIZE) - SIZE;
81: exp = urandom () % SIZE;
82: mpf_random2 (u, size, exp);
83: }
84: else
85: {
86: ulimb = urandom ();
87: mpf_set_ui (u, ulimb);
88: single_flag = 1;
89: }
90:
91: if ((urandom () & 1) != 0)
92: {
93: size = urandom () % (2 * SIZE) - SIZE;
94: exp = urandom () % SIZE;
95: mpf_random2 (v, size, exp);
96: }
97: else
98: {
99: vlimb = urandom ();
100: mpf_set_ui (v, vlimb);
101: single_flag = 2;
102: }
103:
104: if (mpf_sgn (v) == 0)
105: continue;
106:
107: mpf_div (w, u, v);
108: mpf_mul (x, w, v);
109: mpf_reldiff (rerr, u, x);
110: if (mpf_cmp (rerr, limit_rerr) > 0)
111: {
112: printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i);
113: printf (" u = "); mpf_dump (u);
114: printf (" v = "); mpf_dump (v);
115: printf (" x = "); mpf_dump (x);
116: printf (" w = "); mpf_dump (w);
117: abort ();
118: }
119:
120: if (single_flag == 2)
121: {
122: mpf_div_ui (x, u, vlimb);
123: mpf_reldiff (rerr, w, x);
124: if (mpf_cmp (rerr, limit_rerr) > 0)
125: {
126: printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i);
127: printf (" u = "); mpf_dump (u);
128: printf (" v = "); mpf_dump (v);
129: printf (" x = "); mpf_dump (x);
130: printf (" w = "); mpf_dump (w);
131: abort ();
132: }
133: }
134:
135: if (single_flag == 1)
136: {
137: mpf_ui_div (x, ulimb, v);
138: mpf_reldiff (rerr, w, x);
139: if (mpf_cmp (rerr, limit_rerr) > 0)
140: {
141: printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i);
142: printf (" u = "); mpf_dump (u);
143: printf (" v = "); mpf_dump (v);
144: printf (" x = "); mpf_dump (x);
145: printf (" w = "); mpf_dump (w);
146: abort ();
147: }
148: }
149: }
150:
151: mpf_clear (rerr);
152: mpf_clear (limit_rerr);
153:
154: mpf_clear (u);
155: mpf_clear (v);
156: mpf_clear (w);
157: mpf_clear (x);
158:
159: tests_end ();
160: exit (0);
161: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>