1 /* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui.
3 Copyright (C) 1996 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 Library General Public License as published by
9 the Free Software Foundation; either version 2 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 Library General Public
15 License for more details.
17 You should have received a copy of the GNU Library 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. */
40 mp_size_t bprec = 100;
41 mpf_t rerr, limit_rerr;
42 mp_limb_t ulimb, vlimb;
47 reps = strtol (argv[1], 0, 0);
49 bprec = strtol (argv[2], 0, 0);
52 mpf_set_default_prec (bprec);
55 mpf_init (limit_rerr);
62 for (i = 0; i < reps; i++)
66 res_prec = urandom () % (bprec + 100);
67 mpf_set_prec (w, res_prec);
68 mpf_set_prec (x, res_prec);
70 mpf_set_ui (limit_rerr, 1);
71 mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
75 if ((urandom () & 1) != 0)
77 size = urandom () % (2 * SIZE) - SIZE;
78 exp = urandom () % SIZE;
79 mpf_random2 (u, size, exp);
84 mpf_set_ui (u, ulimb);
88 if ((urandom () & 1) != 0)
90 size = urandom () % (2 * SIZE) - SIZE;
91 exp = urandom () % SIZE;
92 mpf_random2 (v, size, exp);
97 mpf_set_ui (v, vlimb);
101 if (mpf_sgn (v) == 0)
106 mpf_reldiff (rerr, u, x);
107 if (mpf_cmp (rerr, limit_rerr) > 0)
109 printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i);
110 printf (" u = "); mpf_dump (u);
111 printf (" v = "); mpf_dump (v);
112 printf (" x = "); mpf_dump (x);
113 printf (" w = "); mpf_dump (w);
117 if (single_flag == 2)
119 mpf_div_ui (x, u, vlimb);
120 mpf_reldiff (rerr, w, x);
121 if (mpf_cmp (rerr, limit_rerr) > 0)
123 printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i);
124 printf (" u = "); mpf_dump (u);
125 printf (" v = "); mpf_dump (v);
126 printf (" x = "); mpf_dump (x);
127 printf (" w = "); mpf_dump (w);
132 if (single_flag == 1)
134 mpf_ui_div (x, ulimb, v);
135 mpf_reldiff (rerr, w, x);
136 if (mpf_cmp (rerr, limit_rerr) > 0)
138 printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i);
139 printf (" u = "); mpf_dump (u);
140 printf (" v = "); mpf_dump (v);
141 printf (" x = "); mpf_dump (x);
142 printf (" w = "); mpf_dump (w);
155 printf (" exp = %ld\n", x->_mp_exp);
156 printf ("size = %d\n", x->_mp_size);
157 for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
158 printf ("%08lX ", x->_mp_d[i]);