~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/tests/mpn/t-mp_bases.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
You should have received a copy of the GNU Lesser General Public License
18
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
 
MA 02111-1307, USA. */
 
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
MA 02110-1301, USA. */
21
21
 
22
22
#include <stdio.h>
23
23
#include <stdlib.h>
30
30
int
31
31
main (int argc, char *argv[])
32
32
{
33
 
  mp_limb_t  bb, h, l, bb_inv;
34
 
  int        i, j;
35
 
 
36
 
  for (i = 2; i < numberof (mp_bases); i++)
37
 
    {
38
 
      if (POW2_P (i))
39
 
        {
40
 
          count_trailing_zeros (j, i);
41
 
          if (mp_bases[i].big_base != (mp_limb_t) j)
42
 
            {
43
 
              printf ("mp_bases[%d].big_base (trailing zeros) wrong\n", i);
44
 
              abort ();
45
 
            }
46
 
        }
47
 
      else
48
 
        {
49
 
          bb = 1;
50
 
          for (j = 0; j < mp_bases[i].chars_per_limb; j++)
51
 
            {
52
 
              umul_ppmm (h, bb, bb, i);
53
 
              if (h != 0 || (bb & GMP_NAIL_MASK) != 0)
54
 
                {
55
 
                  printf ("mp_bases[%d].chars_per_limb overflow\n", i);
56
 
                  abort ();
57
 
                }
58
 
            }
59
 
          umul_ppmm (h, l, bb, i);
60
 
          if (h == 0 && (l & GMP_NAIL_MASK) == 0)
61
 
            {
62
 
              printf ("mp_bases[%d].chars_per_limb too small\n", i);
63
 
              abort ();
64
 
            }
65
 
 
66
 
          if (mp_bases[i].big_base != bb)
67
 
            {
68
 
              printf ("mp_bases[%d].big_base wrong\n", i);
69
 
              abort ();
70
 
            }
71
 
 
72
 
          invert_limb (bb_inv, bb << refmpn_count_leading_zeros (bb));
73
 
          if (mp_bases[i].big_base_inverted != bb_inv)
74
 
            {
75
 
              printf ("mp_bases[%d].big_base_inverted wrong\n", i);
76
 
              abort ();
77
 
            }
78
 
        }
79
 
    }
80
 
 
81
 
  if (MP_BASES_CHARS_PER_LIMB_10 != mp_bases[10].chars_per_limb)
82
 
    {
83
 
      printf ("MP_BASES_CHARS_PER_LIMB_10 not the same as mp_bases[10].chars_per_limb\n");
84
 
      abort ();
85
 
    }
86
 
 
87
 
  if (MP_BASES_BIG_BASE_10 != mp_bases[10].big_base)
88
 
    {
89
 
      printf ("MP_BASES_BIG_BASE_10 not the same as mp_bases[10].big_base\n");
90
 
      abort ();
91
 
    }
92
 
 
93
 
  if (MP_BASES_BIG_BASE_INVERTED_10 != mp_bases[10].big_base_inverted)
94
 
    {
95
 
      printf ("MP_BASES_BIG_BASE_INVERTED_10 not the same as mp_bases[10].big_base_inverted\n");
 
33
  mp_limb_t  want_bb, want_bb_inv;
 
34
  int        base, want_chars_per_limb;
 
35
 
 
36
  want_chars_per_limb = refmpn_chars_per_limb (10);
 
37
  if (MP_BASES_CHARS_PER_LIMB_10 != want_chars_per_limb)
 
38
    {
 
39
      printf ("MP_BASES_CHARS_PER_LIMB_10 wrong\n");
 
40
      abort ();
 
41
    }
 
42
 
 
43
  want_bb = refmpn_big_base (10);
 
44
  if (MP_BASES_BIG_BASE_10 != want_bb)
 
45
    {
 
46
      printf ("MP_BASES_BIG_BASE_10 wrong\n");
 
47
      abort ();
 
48
    }
 
49
 
 
50
  want_bb_inv = refmpn_invert_limb
 
51
    (want_bb << refmpn_count_leading_zeros (want_bb));
 
52
  if (MP_BASES_BIG_BASE_INVERTED_10 != want_bb_inv)
 
53
    {
 
54
      printf ("MP_BASES_BIG_BASE_INVERTED_10 wrong\n");
96
55
      abort ();
97
56
    }
98
57
 
103
62
      abort ();
104
63
    }
105
64
 
 
65
  for (base = 2; base < numberof (mp_bases); base++)
 
66
    {
 
67
      want_chars_per_limb = refmpn_chars_per_limb (base);
 
68
      if (mp_bases[base].chars_per_limb != want_chars_per_limb)
 
69
        {
 
70
          printf ("mp_bases[%d].chars_per_limb wrong\n", base);
 
71
          printf ("  got  %d\n", mp_bases[base].chars_per_limb);
 
72
          printf ("  want %d\n", want_chars_per_limb);
 
73
          abort ();
 
74
        }
 
75
 
 
76
      if (POW2_P (base))
 
77
        {
 
78
          want_bb = refmpn_count_trailing_zeros ((mp_limb_t) base);
 
79
          if (mp_bases[base].big_base != want_bb)
 
80
            {
 
81
              printf ("mp_bases[%d].big_base (log2 of base) wrong\n", base);
 
82
              abort ();
 
83
            }
 
84
        }
 
85
      else
 
86
        {
 
87
          want_bb = refmpn_big_base (base);
 
88
          if (mp_bases[base].big_base != want_bb)
 
89
            {
 
90
              printf ("mp_bases[%d].big_base wrong\n", base);
 
91
              abort ();
 
92
            }
 
93
 
 
94
#if USE_PREINV_DIVREM_1
 
95
          want_bb_inv = refmpn_invert_limb
 
96
            (want_bb << refmpn_count_leading_zeros (want_bb));
 
97
          if (mp_bases[base].big_base_inverted != want_bb_inv)
 
98
            {
 
99
              printf ("mp_bases[%d].big_base_inverted wrong\n", base);
 
100
              abort ();
 
101
            }
 
102
#endif
 
103
        }
 
104
    }
 
105
 
106
106
  exit (0);
107
107
}