Home | History | Annotate | Line # | Download | only in mpn
t-mp_bases.c revision 1.1.1.2
      1      1.1  mrg /* Check mp_bases values.
      2      1.1  mrg 
      3      1.1  mrg Copyright 2002 Free Software Foundation, Inc.
      4      1.1  mrg 
      5  1.1.1.2  mrg This file is part of the GNU MP Library test suite.
      6      1.1  mrg 
      7  1.1.1.2  mrg The GNU MP Library test suite is free software; you can redistribute it
      8  1.1.1.2  mrg and/or modify it under the terms of the GNU General Public License as
      9  1.1.1.2  mrg published by the Free Software Foundation; either version 3 of the License,
     10  1.1.1.2  mrg or (at your option) any later version.
     11  1.1.1.2  mrg 
     12  1.1.1.2  mrg The GNU MP Library test suite is distributed in the hope that it will be
     13  1.1.1.2  mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1.1.2  mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
     15  1.1.1.2  mrg Public License for more details.
     16      1.1  mrg 
     17  1.1.1.2  mrg You should have received a copy of the GNU General Public License along with
     18  1.1.1.2  mrg the GNU MP Library test suite.  If not, see http://www.gnu.org/licenses/.  */
     19      1.1  mrg 
     20      1.1  mrg #include <stdio.h>
     21      1.1  mrg #include <stdlib.h>
     22      1.1  mrg #include "gmp.h"
     23      1.1  mrg #include "gmp-impl.h"
     24      1.1  mrg #include "longlong.h"
     25      1.1  mrg #include "tests.h"
     26      1.1  mrg 
     27      1.1  mrg 
     28      1.1  mrg int
     29      1.1  mrg main (int argc, char *argv[])
     30      1.1  mrg {
     31      1.1  mrg   mp_limb_t  want_bb, want_bb_inv;
     32      1.1  mrg   int        base, want_chars_per_limb;
     33      1.1  mrg 
     34      1.1  mrg   want_chars_per_limb = refmpn_chars_per_limb (10);
     35      1.1  mrg   if (MP_BASES_CHARS_PER_LIMB_10 != want_chars_per_limb)
     36      1.1  mrg     {
     37      1.1  mrg       printf ("MP_BASES_CHARS_PER_LIMB_10 wrong\n");
     38      1.1  mrg       abort ();
     39      1.1  mrg     }
     40      1.1  mrg 
     41      1.1  mrg   want_bb = refmpn_big_base (10);
     42      1.1  mrg   if (MP_BASES_BIG_BASE_10 != want_bb)
     43      1.1  mrg     {
     44      1.1  mrg       printf ("MP_BASES_BIG_BASE_10 wrong\n");
     45      1.1  mrg       abort ();
     46      1.1  mrg     }
     47      1.1  mrg 
     48      1.1  mrg   want_bb_inv = refmpn_invert_limb
     49      1.1  mrg     (want_bb << refmpn_count_leading_zeros (want_bb));
     50      1.1  mrg   if (MP_BASES_BIG_BASE_INVERTED_10 != want_bb_inv)
     51      1.1  mrg     {
     52      1.1  mrg       printf ("MP_BASES_BIG_BASE_INVERTED_10 wrong\n");
     53      1.1  mrg       abort ();
     54      1.1  mrg     }
     55      1.1  mrg 
     56      1.1  mrg   if (MP_BASES_NORMALIZATION_STEPS_10
     57      1.1  mrg       != refmpn_count_leading_zeros (MP_BASES_BIG_BASE_10))
     58      1.1  mrg     {
     59      1.1  mrg       printf ("MP_BASES_NORMALIZATION_STEPS_10 wrong\n");
     60      1.1  mrg       abort ();
     61      1.1  mrg     }
     62      1.1  mrg 
     63      1.1  mrg   for (base = 2; base < numberof (mp_bases); base++)
     64      1.1  mrg     {
     65      1.1  mrg       want_chars_per_limb = refmpn_chars_per_limb (base);
     66      1.1  mrg       if (mp_bases[base].chars_per_limb != want_chars_per_limb)
     67      1.1  mrg         {
     68      1.1  mrg           printf ("mp_bases[%d].chars_per_limb wrong\n", base);
     69      1.1  mrg           printf ("  got  %d\n", mp_bases[base].chars_per_limb);
     70      1.1  mrg           printf ("  want %d\n", want_chars_per_limb);
     71      1.1  mrg           abort ();
     72      1.1  mrg         }
     73      1.1  mrg 
     74      1.1  mrg       if (POW2_P (base))
     75      1.1  mrg         {
     76      1.1  mrg           want_bb = refmpn_count_trailing_zeros ((mp_limb_t) base);
     77      1.1  mrg           if (mp_bases[base].big_base != want_bb)
     78      1.1  mrg             {
     79      1.1  mrg               printf ("mp_bases[%d].big_base (log2 of base) wrong\n", base);
     80      1.1  mrg               abort ();
     81      1.1  mrg             }
     82      1.1  mrg         }
     83      1.1  mrg       else
     84      1.1  mrg         {
     85      1.1  mrg           want_bb = refmpn_big_base (base);
     86      1.1  mrg           if (mp_bases[base].big_base != want_bb)
     87      1.1  mrg             {
     88      1.1  mrg               printf ("mp_bases[%d].big_base wrong\n", base);
     89      1.1  mrg               abort ();
     90      1.1  mrg             }
     91      1.1  mrg 
     92      1.1  mrg #if USE_PREINV_DIVREM_1
     93      1.1  mrg           want_bb_inv = refmpn_invert_limb
     94      1.1  mrg             (want_bb << refmpn_count_leading_zeros (want_bb));
     95      1.1  mrg           if (mp_bases[base].big_base_inverted != want_bb_inv)
     96      1.1  mrg             {
     97      1.1  mrg               printf ("mp_bases[%d].big_base_inverted wrong\n", base);
     98      1.1  mrg               abort ();
     99      1.1  mrg             }
    100      1.1  mrg #endif
    101      1.1  mrg         }
    102      1.1  mrg     }
    103      1.1  mrg 
    104      1.1  mrg   exit (0);
    105      1.1  mrg }
    106