Home | History | Annotate | Line # | Download | only in mpn
      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.3  mrg the GNU MP Library test suite.  If not, see https://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-impl.h"
     23      1.1  mrg #include "longlong.h"
     24      1.1  mrg #include "tests.h"
     25      1.1  mrg 
     26      1.1  mrg 
     27      1.1  mrg int
     28      1.1  mrg main (int argc, char *argv[])
     29      1.1  mrg {
     30      1.1  mrg   mp_limb_t  want_bb, want_bb_inv;
     31      1.1  mrg   int        base, want_chars_per_limb;
     32      1.1  mrg 
     33      1.1  mrg   want_chars_per_limb = refmpn_chars_per_limb (10);
     34      1.1  mrg   if (MP_BASES_CHARS_PER_LIMB_10 != want_chars_per_limb)
     35      1.1  mrg     {
     36      1.1  mrg       printf ("MP_BASES_CHARS_PER_LIMB_10 wrong\n");
     37      1.1  mrg       abort ();
     38      1.1  mrg     }
     39      1.1  mrg 
     40      1.1  mrg   want_bb = refmpn_big_base (10);
     41      1.1  mrg   if (MP_BASES_BIG_BASE_10 != want_bb)
     42      1.1  mrg     {
     43      1.1  mrg       printf ("MP_BASES_BIG_BASE_10 wrong\n");
     44      1.1  mrg       abort ();
     45      1.1  mrg     }
     46      1.1  mrg 
     47      1.1  mrg   want_bb_inv = refmpn_invert_limb
     48      1.1  mrg     (want_bb << refmpn_count_leading_zeros (want_bb));
     49      1.1  mrg   if (MP_BASES_BIG_BASE_INVERTED_10 != want_bb_inv)
     50      1.1  mrg     {
     51      1.1  mrg       printf ("MP_BASES_BIG_BASE_INVERTED_10 wrong\n");
     52      1.1  mrg       abort ();
     53      1.1  mrg     }
     54      1.1  mrg 
     55      1.1  mrg   if (MP_BASES_NORMALIZATION_STEPS_10
     56      1.1  mrg       != refmpn_count_leading_zeros (MP_BASES_BIG_BASE_10))
     57      1.1  mrg     {
     58      1.1  mrg       printf ("MP_BASES_NORMALIZATION_STEPS_10 wrong\n");
     59      1.1  mrg       abort ();
     60      1.1  mrg     }
     61      1.1  mrg 
     62      1.1  mrg   for (base = 2; base < numberof (mp_bases); base++)
     63      1.1  mrg     {
     64      1.1  mrg       want_chars_per_limb = refmpn_chars_per_limb (base);
     65      1.1  mrg       if (mp_bases[base].chars_per_limb != want_chars_per_limb)
     66      1.1  mrg         {
     67      1.1  mrg           printf ("mp_bases[%d].chars_per_limb wrong\n", base);
     68      1.1  mrg           printf ("  got  %d\n", mp_bases[base].chars_per_limb);
     69      1.1  mrg           printf ("  want %d\n", want_chars_per_limb);
     70      1.1  mrg           abort ();
     71      1.1  mrg         }
     72      1.1  mrg 
     73      1.1  mrg       if (POW2_P (base))
     74      1.1  mrg         {
     75      1.1  mrg           want_bb = refmpn_count_trailing_zeros ((mp_limb_t) base);
     76      1.1  mrg           if (mp_bases[base].big_base != want_bb)
     77      1.1  mrg             {
     78      1.1  mrg               printf ("mp_bases[%d].big_base (log2 of base) wrong\n", base);
     79      1.1  mrg               abort ();
     80      1.1  mrg             }
     81      1.1  mrg         }
     82      1.1  mrg       else
     83      1.1  mrg         {
     84      1.1  mrg           want_bb = refmpn_big_base (base);
     85      1.1  mrg           if (mp_bases[base].big_base != want_bb)
     86      1.1  mrg             {
     87      1.1  mrg               printf ("mp_bases[%d].big_base wrong\n", base);
     88      1.1  mrg               abort ();
     89      1.1  mrg             }
     90      1.1  mrg 
     91      1.1  mrg #if USE_PREINV_DIVREM_1
     92      1.1  mrg           want_bb_inv = refmpn_invert_limb
     93      1.1  mrg             (want_bb << refmpn_count_leading_zeros (want_bb));
     94      1.1  mrg           if (mp_bases[base].big_base_inverted != want_bb_inv)
     95      1.1  mrg             {
     96      1.1  mrg               printf ("mp_bases[%d].big_base_inverted wrong\n", base);
     97      1.1  mrg               abort ();
     98      1.1  mrg             }
     99      1.1  mrg #endif
    100      1.1  mrg         }
    101      1.1  mrg     }
    102      1.1  mrg 
    103      1.1  mrg   exit (0);
    104      1.1  mrg }
    105