1 /* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui.
3 Copyright 1996, 2000, 2001, 2003 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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 3 of the License, or (at your
10 option) any later version.
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.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
32 main (int argc, char **argv)
39 mp_size_t bprec = SIZE * GMP_LIMB_BITS;
40 mpf_t rerr, limit_rerr;
41 unsigned long ulimb, vlimb;
48 reps = strtol (argv[1], 0, 0);
50 bprec = strtol (argv[2], 0, 0);
53 mpf_set_default_prec (bprec);
56 mpf_init (limit_rerr);
63 for (i = 0; i < reps; i++)
67 res_prec = urandom () % bprec + 1;
68 mpf_set_prec (w, res_prec);
69 mpf_set_prec (x, res_prec);
71 mpf_set_ui (limit_rerr, 1);
72 mpf_div_2exp (limit_rerr, limit_rerr, res_prec - 1);
76 if ((urandom () & 1) != 0)
78 size = urandom () % (2 * SIZE) - SIZE;
79 exp = urandom () % SIZE;
80 mpf_random2 (u, size, exp);
85 mpf_set_ui (u, ulimb);
89 if ((urandom () & 1) != 0)
91 size = urandom () % (2 * SIZE) - SIZE;
92 exp = urandom () % SIZE;
93 mpf_random2 (v, size, exp);
98 mpf_set_ui (v, vlimb);
102 if (mpf_sgn (v) == 0)
107 mpf_reldiff (rerr, u, x);
108 if (mpf_cmp (rerr, limit_rerr) > 0)
110 printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i);
111 printf (" u = "); mpf_dump (u);
112 printf (" v = "); mpf_dump (v);
113 printf (" x = "); mpf_dump (x);
114 printf (" w = "); mpf_dump (w);
118 if (single_flag == 2)
120 mpf_div_ui (x, u, vlimb);
121 mpf_reldiff (rerr, w, x);
122 if (mpf_cmp (rerr, limit_rerr) > 0)
124 printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i);
125 printf (" u = "); mpf_dump (u);
126 printf (" v = "); mpf_dump (v);
127 printf (" x = "); mpf_dump (x);
128 printf (" w = "); mpf_dump (w);
133 if (single_flag == 1)
135 mpf_ui_div (x, ulimb, v);
136 mpf_reldiff (rerr, w, x);
137 if (mpf_cmp (rerr, limit_rerr) > 0)
139 printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i);
140 printf (" u = "); mpf_dump (u);
141 printf (" v = "); mpf_dump (v);
142 printf (" x = "); mpf_dump (x);
143 printf (" w = "); mpf_dump (w);
150 mpf_clear (limit_rerr);