summaryrefslogtreecommitdiff
path: root/mpz/tests
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2000-12-17 22:50:49 +0100
committerKevin Ryde <user42@zip.com.au>2000-12-17 22:50:49 +0100
commitbdbc69c4f169dd52475911c295dbaa23904a6ed0 (patch)
tree2d41cbfb5e0644e2df238466e29ef47e94ba49a0 /mpz/tests
parentbe870383b8425bf3facb4c2c71d8590868071f98 (diff)
downloadgmp-bdbc69c4f169dd52475911c295dbaa23904a6ed0.tar.gz
* mpz/tests/t-fac_ui.c: New test.
Diffstat (limited to 'mpz/tests')
-rw-r--r--mpz/tests/t-fac_ui.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/mpz/tests/t-fac_ui.c b/mpz/tests/t-fac_ui.c
new file mode 100644
index 000000000..967d1a06c
--- /dev/null
+++ b/mpz/tests/t-fac_ui.c
@@ -0,0 +1,93 @@
+/* Exercise mpz_fac_ui.
+
+Copyright (C) 2000 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+
+
+/* Usage: t-fac_ui [x|num]
+
+ With no arguments testing goes up to the initial value of "limit" below.
+ With a number argument tests are carried that far, or with a literal "x"
+ tests are continued without limit (this being meant only for development
+ purposes). */
+
+
+unsigned long allocate_count = 0;
+void *
+allocate (size_t size)
+{
+ allocate_count++;
+ return __gmp_default_allocate (size);
+}
+void
+release (void *ptr, size_t size)
+{
+ allocate_count--;
+ __gmp_default_free (ptr, size);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ unsigned long n;
+ unsigned long limit = 1500;
+ mpz_t f, r;
+
+ if (argc > 1 && argv[1][0] == 'x')
+ limit = ULONG_MAX;
+ else if (argc > 1)
+ limit = atoi (argv[1]);
+
+ if (BITS_PER_MP_LIMB < BITS_PER_LONGINT)
+ limit = MIN (limit, MP_LIMB_T_MAX);
+
+ mp_set_memory_functions (allocate, NULL, release);
+
+ mpz_init_set_ui (f, 1); /* 0! = 1 */
+ mpz_init (r);
+
+ for (n = 0; n < limit; n++)
+ {
+ mpz_fac_ui (r, n);
+ MPZ_CHECK_FORMAT (r);
+
+ if (mpz_cmp (f, r) != 0)
+ {
+ printf ("mpz_fib_ui(%lu) wrong\n", n);
+ printf (" got "); mpz_out_str (stdout, 10, r); printf("\n");
+ printf (" want "); mpz_out_str (stdout, 10, f); printf("\n");
+ abort ();
+ }
+
+ mpz_mul_ui (f, f, n+1); /* (n+1)! = n! * n */
+ }
+
+ mpz_clear (f);
+ mpz_clear (r);
+
+ ASSERT_ALWAYS (allocate_count == 0);
+
+ exit (0);
+}