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 3 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.  If not, see http://www.gnu.org/licenses/.  */
20
21#include <stdio.h>
22#include <stdlib.h>
23
24#include "gmp.h"
25#include "gmp-impl.h"
26#include "tests.h"
27
28
29void
30check_one (mpz_srcptr a, unsigned long d, int want)
31{
32  int   got;
33
34  got = (mpz_divisible_2exp_p (a, d) != 0);
35  if (want != got)
36    {
37      printf ("mpz_divisible_2exp_p wrong\n");
38      printf ("   expected %d got %d\n", want, got);
39      mpz_trace ("   a", a);
40      printf    ("   d=%lu\n", d);
41      mp_trace_base = -16;
42      mpz_trace ("   a", a);
43      printf    ("   d=0x%lX\n", d);
44      abort ();
45    }
46}
47
48void
49check_data (void)
50{
51  static const struct {
52    const char    *a;
53    unsigned long d;
54    int           want;
55
56  } data[] = {
57
58    { "0", 0, 1 },
59    { "0", 1, 1 },
60    { "0", 2, 1 },
61    { "0", 3, 1 },
62
63    { "1", 0, 1 },
64    { "1", 1, 0 },
65    { "1", 2, 0 },
66    { "1", 3, 0 },
67    { "1", 10000, 0 },
68
69    { "4", 0, 1 },
70    { "4", 1, 1 },
71    { "4", 2, 1 },
72    { "4", 3, 0 },
73    { "4", 4, 0 },
74    { "4", 10000, 0 },
75
76    { "0x80000000", 31, 1 },
77    { "0x80000000", 32, 0 },
78    { "0x80000000", 64, 0 },
79
80    { "0x100000000", 32, 1 },
81    { "0x100000000", 33, 0 },
82    { "0x100000000", 64, 0 },
83
84    { "0x8000000000000000", 63, 1 },
85    { "0x8000000000000000", 64, 0 },
86    { "0x8000000000000000", 128, 0 },
87
88    { "0x10000000000000000", 64, 1 },
89    { "0x10000000000000000", 65, 0 },
90    { "0x10000000000000000", 128, 0 },
91    { "0x10000000000000000", 256, 0 },
92
93    { "0x10000000000000000100000000", 32, 1 },
94    { "0x10000000000000000100000000", 33, 0 },
95    { "0x10000000000000000100000000", 64, 0 },
96
97    { "0x1000000000000000010000000000000000", 64, 1 },
98    { "0x1000000000000000010000000000000000", 65, 0 },
99    { "0x1000000000000000010000000000000000", 128, 0 },
100    { "0x1000000000000000010000000000000000", 256, 0 },
101    { "0x1000000000000000010000000000000000", 1024, 0 },
102
103  };
104
105  mpz_t   a, d;
106  int     i;
107
108  mpz_init (a);
109  mpz_init (d);
110
111  for (i = 0; i < numberof (data); i++)
112    {
113      mpz_set_str_or_abort (a, data[i].a, 0);
114      check_one (a, data[i].d, data[i].want);
115
116      mpz_neg (a, a);
117      check_one (a, data[i].d, data[i].want);
118    }
119
120  mpz_clear (a);
121  mpz_clear (d);
122}
123
124int
125main (int argc, char *argv[])
126{
127  tests_start ();
128
129  check_data ();
130
131  tests_end ();
132  exit (0);
133}
134