1 /* Test mpf_div, mpf_div_2exp, mpf_mul_2exp.
3 Copyright 1996, 2000, 2001 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)
36 mpf_t u, v, w1, w2, w3;
37 mp_size_t bprec = 100;
38 mpf_t rerr, limit_rerr;
46 reps = strtol (argv[1], 0, 0);
48 bprec = strtol (argv[2], 0, 0);
51 mpf_set_default_prec (bprec);
54 mpf_init (limit_rerr);
62 for (i = 0; i < reps; i++)
64 unsigned long int res_prec;
65 unsigned long int pow2;
67 res_prec = urandom () % (bprec + 100);
68 mpf_set_prec (w1, res_prec);
69 mpf_set_prec (w2, res_prec);
70 mpf_set_prec (w3, res_prec);
72 mpf_set_ui (limit_rerr, 1);
73 mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
75 pow2 = urandom () % 0x10000;
77 mpf_mul_2exp (v, v, pow2);
79 un = urandom () % (2 * SIZE) - SIZE;
80 ue = urandom () % SIZE;
81 mpf_random2 (u, un, ue);
83 mpf_div_2exp (w1, u, pow2);
85 mpf_reldiff (rerr, w1, w2);
86 if (mpf_cmp (rerr, limit_rerr) > 0)
88 printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i);
89 printf (" u = "); mpf_dump (u);
90 printf (" v = "); mpf_dump (v);
91 printf (" w1 = "); mpf_dump (w1);
92 printf (" w2 = "); mpf_dump (w2);
95 mpf_mul_2exp (w3, w1, pow2);
96 mpf_reldiff (rerr, u, w3);
97 if (mpf_cmp (rerr, limit_rerr) > 0)
99 printf ("ERROR in mpf_mul_2exp after %d tests\n", i);
100 printf (" u = "); mpf_dump (u);
101 printf (" v = "); mpf_dump (v);
102 printf (" w1 = "); mpf_dump (w1);
103 printf (" w3 = "); mpf_dump (w3);
109 mpf_clear (limit_rerr);