1 /* Exercise mpz_fac_ui.
3 Copyright 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/. */
27 /* Usage: t-fac_ui [x|num]
29 With no arguments testing goes up to the initial value of "limit" below.
30 With a number argument tests are carried that far, or with a literal "x"
31 tests are continued without limit (this being meant only for development
36 main (int argc, char *argv[])
39 unsigned long limit = 1500;
44 if (argc > 1 && argv[1][0] == 'x')
47 limit = atoi (argv[1]);
49 /* for small limb testing */
50 limit = MIN (limit, MP_LIMB_T_MAX);
52 mpz_init_set_ui (f, 1); /* 0! = 1 */
55 for (n = 0; n < limit; n++)
60 if (mpz_cmp (f, r) != 0)
62 printf ("mpz_fac_ui(%lu) wrong\n", n);
63 printf (" got "); mpz_out_str (stdout, 10, r); printf("\n");
64 printf (" want "); mpz_out_str (stdout, 10, f); printf("\n");
68 mpz_mul_ui (f, f, n+1); /* (n+1)! = n! * (n+1) */