diff --git a/gmp-h.in b/gmp-h.in index 897d7db7..738ea340 100644 --- a/gmp-h.in +++ b/gmp-h.in @@ -817,6 +817,9 @@ __GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, int #define mpz_fac_ui __gmpz_fac_ui __GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_2fac_ui __gmpz_2fac_ui +__GMP_DECLSPEC void mpz_2fac_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + #define mpz_fdiv_q __gmpz_fdiv_q __GMP_DECLSPEC void mpz_fdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); diff --git a/mpz/2fac_ui.c b/mpz/2fac_ui.c index ba00c456..10db89a3 100644 --- a/mpz/2fac_ui.c +++ b/mpz/2fac_ui.c @@ -19,7 +19,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ -#include "gmp.h" +#include "mpir.h" #include "gmp-impl.h" #if GMP_LIMB_BITS == 64 diff --git a/mpz/lucnum2_ui.c b/mpz/lucnum2_ui.c index fa09d5ca..733bd8f9 100644 --- a/mpz/lucnum2_ui.c +++ b/mpz/lucnum2_ui.c @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include -#include "gmp.h" +#include "mpir.h" #include "gmp-impl.h" diff --git a/mpz/lucnum_ui.c b/mpz/lucnum_ui.c index cf0b7c5c..1db0d998 100644 --- a/mpz/lucnum_ui.c +++ b/mpz/lucnum_ui.c @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include -#include "gmp.h" +#include "mpir.h" #include "gmp-impl.h" diff --git a/nextprime.c b/nextprime.c index f0b01d62..f27f1fb8 100644 --- a/nextprime.c +++ b/nextprime.c @@ -41,7 +41,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ division. */ -#include "gmp.h" +#include "mpir.h" #include "gmp-impl.h" #include /* for memset */ diff --git a/primesieve.c b/primesieve.c index d1bf5a16..a135692b 100644 --- a/primesieve.c +++ b/primesieve.c @@ -24,7 +24,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ -#include "gmp.h" +#include "mpir.h" #include "gmp-impl.h" /**************************************************************/ diff --git a/tests/mpz/t-fac_ui.c b/tests/mpz/t-fac_ui.c index 053e720c..f6f84a99 100644 --- a/tests/mpz/t-fac_ui.c +++ b/tests/mpz/t-fac_ui.c @@ -1,23 +1,21 @@ -/* Exercise mpz_fac_ui. +/* Exercise mpz_fac_ui and mpz_2fac_ui. -Copyright 2000, 2001, 2002 Free Software Foundation, Inc. +Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc. -This file is part of the GNU MP Library. +This file is part of the GNU MP Library test suite. -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 test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 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. +The GNU MP Library test suite 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 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., 51 Franklin Street, Fifth Floor, Boston, -MA 02110-1301, USA. */ +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */ #include #include @@ -25,7 +23,6 @@ MA 02110-1301, USA. */ #include "gmp-impl.h" #include "tests.h" -#define printf gmp_printf /* Usage: t-fac_ui [x|num] @@ -38,39 +35,68 @@ MA 02110-1301, USA. */ int main (int argc, char *argv[]) { - mpir_ui n; - mpir_ui limit = 1500; - mpz_t f, r; + unsigned long n, m; + unsigned long limit = 2222; + mpz_t df[2], f, r; tests_start (); if (argc > 1 && argv[1][0] == 'x') - limit = GMP_UI_MAX; + limit = ULONG_MAX; else if (argc > 1) limit = atoi (argv[1]); /* for small limb testing */ limit = MIN (limit, MP_LIMB_T_MAX); + mpz_init_set_ui (df[0], 1); /* 0!! = 1 */ + mpz_init_set_ui (df[1], 1); /* -1!! = 1 */ mpz_init_set_ui (f, 1); /* 0! = 1 */ mpz_init (r); - for (n = 0; n < limit; n++) + for (n = 0, m = 0; n < limit; n++) { mpz_fac_ui (r, n); MPZ_CHECK_FORMAT (r); if (mpz_cmp (f, r) != 0) { - printf ("mpz_fac_ui(%Mu) wrong\n", n); + printf ("mpz_fac_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_2fac_ui (r, n); + MPZ_CHECK_FORMAT (r); + + if (mpz_cmp (df[m], r) != 0) + { + printf ("mpz_2fac_ui(%lu) wrong\n", n); + printf (" got "); mpz_out_str (stdout, 10, r); printf("\n"); + printf (" want "); mpz_out_str (stdout, 10, df[m]); printf("\n"); + abort (); + } + + m ^= 1; + mpz_mul_ui (df[m], df[m], n+1); /* (n+1)!! = (n-1)!! * (n+1) */ + mpz_mul_ui (f, f, n+1); /* (n+1)! = n! * (n+1) */ } + n = 1048573; /* a prime */ + if (n > MP_LIMB_T_MAX) + n = 65521; /* a smaller prime :-) */ + mpz_fac_ui (f, n - 1); + m = mpz_fdiv_ui (f, n); + if ( m != n - 1) + { + printf ("mpz_fac_ui(%lu) wrong\n", n - 1); + printf (" Wilson's theorem not verified: got %lu, expected %lu.\n",m ,n - 1); + abort (); + } + + mpz_clear (df[0]); + mpz_clear (df[1]); mpz_clear (f); mpz_clear (r);