1 /* Test that routines allow reusing a source variable as destination.
3 Copyright 1996, 2000, 2001, 2002 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/. */
30 /* FIXME: When linking to a DLL libgmp, mpf_add etc can't be used as
31 initializers for global variables because they're effectively global
32 variables (function pointers) themselves. Perhaps calling a test
33 function successively with mpf_add etc would be better. */
38 printf ("Test suppressed for windows DLL\n");
43 #else /* ! DLL_EXPORT */
53 void dump_abort __GMP_PROTO ((char *, mpf_t, mpf_t));
55 typedef void (*dss_func) __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
57 dss_func dss_funcs[] =
59 mpf_div, mpf_add, mpf_mul, mpf_sub,
62 char *dss_func_names[] =
64 "mpf_div", "mpf_add", "mpf_mul", "mpf_sub",
67 typedef void (*dsi_func) __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
69 dsi_func dsi_funcs[] =
71 mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
72 mpf_mul_2exp, mpf_div_2exp
75 char *dsi_func_names[] =
77 "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
78 "mpf_mul_2exp", "mpf_div_2exp"
81 typedef void (*dis_func) __GMP_PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
83 dis_func dis_funcs[] =
85 mpf_ui_div, mpf_ui_sub,
88 char *dis_func_names[] =
90 "mpf_ui_div", "mpf_ui_sub",
94 main (int argc, char **argv)
97 int pass, reps = 10000;
99 unsigned long int in1i, in2i;
100 mpf_t res1, res2, res3;
101 mp_size_t bprec = 100;
107 reps = strtol (argv[1], 0, 0);
109 bprec = strtol (argv[2], 0, 0);
112 mpf_set_default_prec (bprec);
121 for (pass = 1; pass <= reps; pass++)
123 mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO);
124 mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO);
126 for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
128 /* Don't divide by 0. */
129 if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
132 (dss_funcs[i]) (res1, in1, in2);
135 (dss_funcs[i]) (out1, out1, in2);
136 mpf_set (res2, out1);
139 (dss_funcs[i]) (out1, in1, out1);
140 mpf_set (res3, out1);
142 if (mpf_cmp (res1, res2) != 0)
143 dump_abort (dss_func_names[i], res1, res2);
144 if (mpf_cmp (res1, res3) != 0)
145 dump_abort (dss_func_names[i], res1, res3);
149 for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
151 /* Don't divide by 0. */
152 if (strcmp (dsi_func_names[i], "mpf_div_ui") == 0 && in2i == 0)
155 (dsi_funcs[i]) (res1, in1, in2i);
158 (dsi_funcs[i]) (out1, out1, in2i);
159 mpf_set (res2, out1);
161 if (mpf_cmp (res1, res2) != 0)
162 dump_abort (dsi_func_names[i], res1, res2);
166 for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
168 /* Don't divide by 0. */
169 if (strcmp (dis_func_names[i], "mpf_ui_div") == 0
170 && mpf_cmp_ui (in2, 0) == 0)
173 (dis_funcs[i]) (res1, in1i, in2);
176 (dis_funcs[i]) (out1, in1i, out1);
177 mpf_set (res2, out1);
179 if (mpf_cmp (res1, res2) != 0)
180 dump_abort (dis_func_names[i], res1, res2);
197 dump_abort (char *name, mpf_t res1, mpf_t res2)
199 printf ("failure in %s:\n", name);
206 void mpf_abs __GMP_PROTO ((mpf_ptr, mpf_srcptr));
207 void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr));
208 void mpf_neg __GMP_PROTO ((mpf_ptr, mpf_srcptr));
211 #endif /* ! DLL_EXPORT */