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