Home | History | Annotate | Line # | Download | only in mpz
t-mfac_uiui.c revision 1.1.1.1.8.2
      1  1.1.1.1.8.2  tls /* Exercise mpz_mfac_uiui.
      2  1.1.1.1.8.2  tls 
      3  1.1.1.1.8.2  tls Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
      4  1.1.1.1.8.2  tls 
      5  1.1.1.1.8.2  tls This file is part of the GNU MP Library test suite.
      6  1.1.1.1.8.2  tls 
      7  1.1.1.1.8.2  tls The GNU MP Library test suite is free software; you can redistribute it
      8  1.1.1.1.8.2  tls and/or modify it under the terms of the GNU General Public License as
      9  1.1.1.1.8.2  tls published by the Free Software Foundation; either version 3 of the License,
     10  1.1.1.1.8.2  tls or (at your option) any later version.
     11  1.1.1.1.8.2  tls 
     12  1.1.1.1.8.2  tls The GNU MP Library test suite is distributed in the hope that it will be
     13  1.1.1.1.8.2  tls useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1.1.1.8.2  tls MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
     15  1.1.1.1.8.2  tls Public License for more details.
     16  1.1.1.1.8.2  tls 
     17  1.1.1.1.8.2  tls You should have received a copy of the GNU General Public License along with
     18  1.1.1.1.8.2  tls the GNU MP Library test suite.  If not, see http://www.gnu.org/licenses/.  */
     19  1.1.1.1.8.2  tls 
     20  1.1.1.1.8.2  tls #include <stdio.h>
     21  1.1.1.1.8.2  tls #include <stdlib.h>
     22  1.1.1.1.8.2  tls #include "gmp.h"
     23  1.1.1.1.8.2  tls #include "gmp-impl.h"
     24  1.1.1.1.8.2  tls #include "tests.h"
     25  1.1.1.1.8.2  tls 
     26  1.1.1.1.8.2  tls 
     27  1.1.1.1.8.2  tls /* Usage: t-mfac_uiui [x|num]
     28  1.1.1.1.8.2  tls 
     29  1.1.1.1.8.2  tls    With no arguments testing goes up to the initial value of "limit" below.
     30  1.1.1.1.8.2  tls    With a number argument tests are carried that far, or with a literal "x"
     31  1.1.1.1.8.2  tls    tests are continued without limit (this being meant only for development
     32  1.1.1.1.8.2  tls    purposes).  */
     33  1.1.1.1.8.2  tls 
     34  1.1.1.1.8.2  tls #define MULTIFAC_WHEEL (2*3*11)
     35  1.1.1.1.8.2  tls #define MULTIFAC_WHEEL2 (5*13)
     36  1.1.1.1.8.2  tls 
     37  1.1.1.1.8.2  tls int
     38  1.1.1.1.8.2  tls main (int argc, char *argv[])
     39  1.1.1.1.8.2  tls {
     40  1.1.1.1.8.2  tls   mpz_t ref[MULTIFAC_WHEEL], ref2[MULTIFAC_WHEEL2], res;
     41  1.1.1.1.8.2  tls   unsigned long n, j, m, m2;
     42  1.1.1.1.8.2  tls   unsigned long limit = 2222, step = 1;
     43  1.1.1.1.8.2  tls 
     44  1.1.1.1.8.2  tls   tests_start ();
     45  1.1.1.1.8.2  tls 
     46  1.1.1.1.8.2  tls   if (argc > 1 && argv[1][0] == 'x')
     47  1.1.1.1.8.2  tls     limit = ULONG_MAX;
     48  1.1.1.1.8.2  tls   else if (argc > 1)
     49  1.1.1.1.8.2  tls     limit = atoi (argv[1]);
     50  1.1.1.1.8.2  tls 
     51  1.1.1.1.8.2  tls   /* for small limb testing */
     52  1.1.1.1.8.2  tls   limit = MIN (limit, MP_LIMB_T_MAX);
     53  1.1.1.1.8.2  tls 
     54  1.1.1.1.8.2  tls   for (m = 0; m < MULTIFAC_WHEEL; m++)
     55  1.1.1.1.8.2  tls     mpz_init_set_ui(ref [m],1);
     56  1.1.1.1.8.2  tls   for (m2 = 0; m2 < MULTIFAC_WHEEL2; m2++)
     57  1.1.1.1.8.2  tls     mpz_init_set_ui(ref2 [m2],1);
     58  1.1.1.1.8.2  tls 
     59  1.1.1.1.8.2  tls   mpz_init (res);
     60  1.1.1.1.8.2  tls 
     61  1.1.1.1.8.2  tls   m = 0;
     62  1.1.1.1.8.2  tls   m2 = 0;
     63  1.1.1.1.8.2  tls   for (n = 0; n <= limit;)
     64  1.1.1.1.8.2  tls     {
     65  1.1.1.1.8.2  tls       mpz_mfac_uiui (res, n, MULTIFAC_WHEEL);
     66  1.1.1.1.8.2  tls       MPZ_CHECK_FORMAT (res);
     67  1.1.1.1.8.2  tls       if (mpz_cmp (ref[m], res) != 0)
     68  1.1.1.1.8.2  tls         {
     69  1.1.1.1.8.2  tls           printf ("mpz_mfac_uiui(%lu,%d) wrong\n", n, MULTIFAC_WHEEL);
     70  1.1.1.1.8.2  tls           printf ("  got  "); mpz_out_str (stdout, 10, res); printf("\n");
     71  1.1.1.1.8.2  tls           printf ("  want "); mpz_out_str (stdout, 10, ref[m]); printf("\n");
     72  1.1.1.1.8.2  tls           abort ();
     73  1.1.1.1.8.2  tls         }
     74  1.1.1.1.8.2  tls       mpz_mfac_uiui (res, n, MULTIFAC_WHEEL2);
     75  1.1.1.1.8.2  tls       MPZ_CHECK_FORMAT (res);
     76  1.1.1.1.8.2  tls       if (mpz_cmp (ref2[m2], res) != 0)
     77  1.1.1.1.8.2  tls         {
     78  1.1.1.1.8.2  tls           printf ("mpz_mfac_uiui(%lu,%d) wrong\n", n, MULTIFAC_WHEEL2);
     79  1.1.1.1.8.2  tls           printf ("  got  "); mpz_out_str (stdout, 10, res); printf("\n");
     80  1.1.1.1.8.2  tls           printf ("  want "); mpz_out_str (stdout, 10, ref2[m2]); printf("\n");
     81  1.1.1.1.8.2  tls           abort ();
     82  1.1.1.1.8.2  tls         }
     83  1.1.1.1.8.2  tls       if (n + step <= limit)
     84  1.1.1.1.8.2  tls 	for (j = 0; j < step; j++) {
     85  1.1.1.1.8.2  tls 	  n++; m++; m2++;
     86  1.1.1.1.8.2  tls 	  if (m >= MULTIFAC_WHEEL) m -= MULTIFAC_WHEEL;
     87  1.1.1.1.8.2  tls 	  if (m2 >= MULTIFAC_WHEEL2) m2 -= MULTIFAC_WHEEL2;
     88  1.1.1.1.8.2  tls 	  mpz_mul_ui (ref[m], ref[m], n); /* Compute a reference, with current library */
     89  1.1.1.1.8.2  tls 	  mpz_mul_ui (ref2[m2], ref2[m2], n); /* Compute a reference, with current library */
     90  1.1.1.1.8.2  tls 	}
     91  1.1.1.1.8.2  tls       else n += step;
     92  1.1.1.1.8.2  tls     }
     93  1.1.1.1.8.2  tls   mpz_fac_ui (ref[0], n);
     94  1.1.1.1.8.2  tls   mpz_mfac_uiui (res, n, 1);
     95  1.1.1.1.8.2  tls   MPZ_CHECK_FORMAT (res);
     96  1.1.1.1.8.2  tls   if (mpz_cmp (ref[0], res) != 0)
     97  1.1.1.1.8.2  tls     {
     98  1.1.1.1.8.2  tls       printf ("mpz_mfac_uiui(%lu,1) wrong\n", n);
     99  1.1.1.1.8.2  tls       printf ("  got  "); mpz_out_str (stdout, 10, res); printf("\n");
    100  1.1.1.1.8.2  tls       printf ("  want "); mpz_out_str (stdout, 10, ref[0]); printf("\n");
    101  1.1.1.1.8.2  tls       abort ();
    102  1.1.1.1.8.2  tls     }
    103  1.1.1.1.8.2  tls 
    104  1.1.1.1.8.2  tls   mpz_2fac_ui (ref[0], n);
    105  1.1.1.1.8.2  tls   mpz_mfac_uiui (res, n, 2);
    106  1.1.1.1.8.2  tls   MPZ_CHECK_FORMAT (res);
    107  1.1.1.1.8.2  tls   if (mpz_cmp (ref[0], res) != 0)
    108  1.1.1.1.8.2  tls     {
    109  1.1.1.1.8.2  tls       printf ("mpz_mfac_uiui(%lu,1) wrong\n", n);
    110  1.1.1.1.8.2  tls       printf ("  got  "); mpz_out_str (stdout, 10, res); printf("\n");
    111  1.1.1.1.8.2  tls       printf ("  want "); mpz_out_str (stdout, 10, ref[0]); printf("\n");
    112  1.1.1.1.8.2  tls       abort ();
    113  1.1.1.1.8.2  tls     }
    114  1.1.1.1.8.2  tls 
    115  1.1.1.1.8.2  tls   n++;
    116  1.1.1.1.8.2  tls   mpz_2fac_ui (ref[0], n);
    117  1.1.1.1.8.2  tls   mpz_mfac_uiui (res, n, 2);
    118  1.1.1.1.8.2  tls   MPZ_CHECK_FORMAT (res);
    119  1.1.1.1.8.2  tls   if (mpz_cmp (ref[0], res) != 0)
    120  1.1.1.1.8.2  tls     {
    121  1.1.1.1.8.2  tls       printf ("mpz_mfac_uiui(%lu,2) wrong\n", n);
    122  1.1.1.1.8.2  tls       printf ("  got  "); mpz_out_str (stdout, 10, res); printf("\n");
    123  1.1.1.1.8.2  tls       printf ("  want "); mpz_out_str (stdout, 10, ref[0]); printf("\n");
    124  1.1.1.1.8.2  tls       abort ();
    125  1.1.1.1.8.2  tls     }
    126  1.1.1.1.8.2  tls 
    127  1.1.1.1.8.2  tls   for (m = 0; m < MULTIFAC_WHEEL; m++)
    128  1.1.1.1.8.2  tls     mpz_clear (ref[m]);
    129  1.1.1.1.8.2  tls   for (m2 = 0; m2 < MULTIFAC_WHEEL2; m2++)
    130  1.1.1.1.8.2  tls     mpz_clear (ref2[m2]);
    131  1.1.1.1.8.2  tls   mpz_clear (res);
    132  1.1.1.1.8.2  tls 
    133  1.1.1.1.8.2  tls   tests_end ();
    134  1.1.1.1.8.2  tls 
    135  1.1.1.1.8.2  tls   exit (0);
    136  1.1.1.1.8.2  tls }
    137