Annotation of OpenXM_contrib/gmp/tests/mpz/t-fac_ui.c, Revision 1.1
1.1 ! ohara 1: /* Exercise mpz_fac_ui.
! 2:
! 3: Copyright 2000, 2001 Free Software Foundation, Inc.
! 4:
! 5: This file is part of the GNU MP Library.
! 6:
! 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 2.1 of the License, or (at your
! 10: option) any later version.
! 11:
! 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.
! 16:
! 17: You should have received a copy of the GNU Lesser 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. */
! 21:
! 22: #include <stdio.h>
! 23: #include <stdlib.h>
! 24: #include "gmp.h"
! 25: #include "gmp-impl.h"
! 26: #include "tests.h"
! 27:
! 28:
! 29: /* Usage: t-fac_ui [x|num]
! 30:
! 31: With no arguments testing goes up to the initial value of "limit" below.
! 32: With a number argument tests are carried that far, or with a literal "x"
! 33: tests are continued without limit (this being meant only for development
! 34: purposes). */
! 35:
! 36:
! 37: int
! 38: main (int argc, char *argv[])
! 39: {
! 40: unsigned long n;
! 41: unsigned long limit = 1500;
! 42: mpz_t f, r;
! 43:
! 44: tests_start ();
! 45:
! 46: if (argc > 1 && argv[1][0] == 'x')
! 47: limit = ULONG_MAX;
! 48: else if (argc > 1)
! 49: limit = atoi (argv[1]);
! 50:
! 51: /* for small limb testing */
! 52: limit = MIN (limit, MP_LIMB_T_MAX);
! 53:
! 54: mpz_init_set_ui (f, 1); /* 0! = 1 */
! 55: mpz_init (r);
! 56:
! 57: for (n = 0; n < limit; n++)
! 58: {
! 59: mpz_fac_ui (r, n);
! 60: MPZ_CHECK_FORMAT (r);
! 61:
! 62: if (mpz_cmp (f, r) != 0)
! 63: {
! 64: printf ("mpz_fib_ui(%lu) wrong\n", n);
! 65: printf (" got "); mpz_out_str (stdout, 10, r); printf("\n");
! 66: printf (" want "); mpz_out_str (stdout, 10, f); printf("\n");
! 67: abort ();
! 68: }
! 69:
! 70: mpz_mul_ui (f, f, n+1); /* (n+1)! = n! * n */
! 71: }
! 72:
! 73: mpz_clear (f);
! 74: mpz_clear (r);
! 75:
! 76: tests_end ();
! 77:
! 78: exit (0);
! 79: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>