blob: b6f23668d5d54c6225da480604fb2d5a7397675d [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/* Test ULONG_PARITY.
2
3Copyright 2002, 2014 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the 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 "tests.h"
24
25void
26check_one (int want, unsigned long n)
27{
28 int got;
29 ULONG_PARITY (got, n);
30 if (got != want)
31 {
32 printf ("ULONG_PARITY wrong\n");
33 printf (" n %lX\n", n);
34 printf (" want %d\n", want);
35 printf (" got %d\n", got);
36 abort ();
37 }
38}
39
40void
41check_various (void)
42{
43 int i;
44
45 check_one (0, 0L);
46 check_one (BITS_PER_ULONG & 1, ULONG_MAX);
47 check_one (0, 0x11L);
48 check_one (1, 0x111L);
49 check_one (1, 0x3111L);
50
51 for (i = 0; i < BITS_PER_ULONG; i++)
52 check_one (1, 1UL << i);
53}
54
55
56int
57main (int argc, char *argv[])
58{
59 tests_start ();
60 mp_trace_base = 16;
61
62 check_various ();
63
64 tests_end ();
65 exit (0);
66}