1/* Check mp_bases values. 2 3Copyright 2002 Free Software Foundation, Inc. 4 5This file is part of the GNU MP Library. 6 7The GNU MP Library is free software; you can redistribute it and/or modify 8it under the terms of the GNU Lesser General Public License as published by 9the Free Software Foundation; either version 3 of the License, or (at your 10option) any later version. 11 12The GNU MP Library is distributed in the hope that it will be useful, but 13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15License for more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with the GNU MP Library. 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 28int 29main (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