1 /* Copyright 2012 Free Software Foundation, Inc.
3 This file is part of the GNU MP Library test suite.
5 The GNU MP Library test suite is free software; you can redistribute it
6 and/or modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3 of the License,
8 or (at your option) any later version.
10 The GNU MP Library test suite is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */
19 #include <stdlib.h> /* for strtol */
20 #include <stdio.h> /* for printf */
25 #include "tests/tests.h"
31 main (int argc, char **argv)
33 gmp_randstate_ptr rands;
35 mp_ptr ap, rp, pp, app, scratch;
45 count = strtol (argv[1], &end, 0);
46 if (*end || count <= 0)
48 fprintf (stderr, "Invalid test count: %s.\n", argv[1]);
56 ap = TMP_ALLOC_LIMBS (MAX_LIMBS);
57 rp = TMP_ALLOC_LIMBS (MAX_LIMBS);
58 pp = TMP_ALLOC_LIMBS (MAX_LIMBS);
59 app = TMP_ALLOC_LIMBS (MAX_LIMBS);
60 scratch = TMP_ALLOC_LIMBS (5*MAX_LIMBS);
62 for (i = 0; i < count; i++)
68 n = 1 + gmp_urandomm_ui (rands, MAX_LIMBS);
87 mpn_brootinv (rp, ap, n, k, scratch);
88 mpn_powlo (pp, rp, &k, 1, n, scratch);
89 mpn_mullo_n (app, ap, pp, n);
91 if (app[0] != 1 || !mpn_zero_p (app+1, n-1))
94 "mpn_brootinv returned bad result: %u limbs\n",
96 gmp_fprintf (stderr, "k = %Mx\n", k);
97 gmp_fprintf (stderr, "a = %Nx\n", ap, n);
98 gmp_fprintf (stderr, "r = %Nx\n", rp, n);
99 gmp_fprintf (stderr, "r^n = %Nx\n", pp, n);
100 gmp_fprintf (stderr, "a r^n = %Nx\n", app, n);