source: trunk/third/gmp/tests/mpz/t-divis_2exp.c @ 18191

Revision 18191, 3.0 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* test mpz_divisible_2exp_p */
2
3/*
4Copyright 2001 Free Software Foundation, Inc.
5
6This file is part of the GNU MP Library.
7
8The GNU MP Library is free software; you can redistribute it and/or modify
9it under the terms of the GNU Lesser General Public License as published by
10the Free Software Foundation; either version 2.1 of the License, or (at your
11option) any later version.
12
13The GNU MP Library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21MA 02111-1307, USA.
22*/
23
24#include <stdio.h>
25#include <stdlib.h>
26
27#include "gmp.h"
28#include "gmp-impl.h"
29#include "tests.h"
30
31
32void
33check_one (mpz_srcptr a, unsigned long d, int want)
34{
35  int   got;
36
37  got = (mpz_divisible_2exp_p (a, d) != 0);
38  if (want != got)
39    {
40      printf ("mpz_divisible_2exp_p wrong\n");
41      printf ("   expected %d got %d\n", want, got);
42      mpz_trace ("   a", a);
43      printf    ("   d=%lu\n", d);
44      mp_trace_base = -16;
45      mpz_trace ("   a", a);
46      printf    ("   d=0x%lX\n", d);
47      abort ();
48    }
49}
50
51void
52check_data (void)
53{
54  static const struct {
55    const char    *a;
56    unsigned long d;
57    int           want;
58
59  } data[] = {
60
61    { "0", 0, 1 },
62    { "0", 1, 1 },
63    { "0", 2, 1 },
64    { "0", 3, 1 },
65
66    { "1", 0, 1 },
67    { "1", 1, 0 },
68    { "1", 2, 0 },
69    { "1", 3, 0 },
70    { "1", 10000, 0 },
71
72    { "4", 0, 1 },
73    { "4", 1, 1 },
74    { "4", 2, 1 },
75    { "4", 3, 0 },
76    { "4", 4, 0 },
77    { "4", 10000, 0 },
78
79    { "0x80000000", 31, 1 },
80    { "0x80000000", 32, 0 },
81    { "0x80000000", 64, 0 },
82
83    { "0x100000000", 32, 1 },
84    { "0x100000000", 33, 0 },
85    { "0x100000000", 64, 0 },
86
87    { "0x8000000000000000", 63, 1 },
88    { "0x8000000000000000", 64, 0 },
89    { "0x8000000000000000", 128, 0 },
90
91    { "0x10000000000000000", 64, 1 },
92    { "0x10000000000000000", 65, 0 },
93    { "0x10000000000000000", 128, 0 },
94    { "0x10000000000000000", 256, 0 },
95
96    { "0x10000000000000000100000000", 32, 1 },
97    { "0x10000000000000000100000000", 33, 0 },
98    { "0x10000000000000000100000000", 64, 0 },
99
100    { "0x1000000000000000010000000000000000", 64, 1 },
101    { "0x1000000000000000010000000000000000", 65, 0 },
102    { "0x1000000000000000010000000000000000", 128, 0 },
103    { "0x1000000000000000010000000000000000", 256, 0 },
104    { "0x1000000000000000010000000000000000", 1024, 0 },
105
106  };
107
108  mpz_t   a, d;
109  int     i;
110
111  mpz_init (a);
112  mpz_init (d);
113
114  for (i = 0; i < numberof (data); i++)
115    {
116      mpz_set_str_or_abort (a, data[i].a, 0);
117      check_one (a, data[i].d, data[i].want);
118
119      mpz_neg (a, a);
120      check_one (a, data[i].d, data[i].want);
121    }
122
123  mpz_clear (a);
124  mpz_clear (d);
125}
126
127int
128main (int argc, char *argv[])
129{
130  tests_start ();
131
132  check_data ();
133
134  tests_end ();
135  exit (0);
136}
Note: See TracBrowser for help on using the repository browser.