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