Skip to content

Commit

Permalink
Added t-fac_ui test code and changed gmp.h => mpir.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbhart committed Feb 28, 2014
1 parent 024bca7 commit abc2bd4
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
3 changes: 3 additions & 0 deletions gmp-h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion mpz/2fac_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mpz/lucnum2_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include "gmp.h"
#include "mpir.h"
#include "gmp-impl.h"


Expand Down
2 changes: 1 addition & 1 deletion mpz/lucnum_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include "gmp.h"
#include "mpir.h"
#include "gmp-impl.h"


Expand Down
2 changes: 1 addition & 1 deletion nextprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h> /* for memset */

Expand Down
2 changes: 1 addition & 1 deletion primesieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**************************************************************/
Expand Down
72 changes: 49 additions & 23 deletions tests/mpz/t-fac_ui.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
/* 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 <stdio.h>
#include <stdlib.h>
#include "mpir.h"
#include "gmp-impl.h"
#include "tests.h"

#define printf gmp_printf

/* Usage: t-fac_ui [x|num]
Expand All @@ -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);

Expand Down

0 comments on commit abc2bd4

Please sign in to comment.