blob: 39b1f35cf4e7d3df90bf4e88f43722f37d0698c0 [file] [log] [blame]
Austin Schuhbb1338c2024-06-15 19:31:16 -07001/*
2
3Copyright 2012, 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 <limits.h>
21#include <stdlib.h>
22#include <stdio.h>
23
24#include "testutils.h"
25
26#define MAXBITS 400
27#define COUNT 10000
28
29void
30testmain (int argc, char **argv)
31{
32 unsigned i;
33 mpz_t a;
34 mp_bitcnt_t b, res, ref;
35
36 mpz_init (a);
37
38 for (i = 0; i < COUNT; i++)
39 {
40 mini_random_scan_op (OP_SCAN0, MAXBITS, a, &b, &ref);
41 res = mpz_scan0 (a, b);
42 if (res != ref)
43 {
44 fprintf (stderr, "mpz_scan0 failed:\n");
45 dump ("a", a);
46 fprintf (stderr, "b: %lu\n", b);
47 fprintf (stderr, "r: %lu\n", res);
48 fprintf (stderr, "ref: %lu\n", ref);
49 abort ();
50 }
51 if (mpz_sgn (a) > 0 && ref < mpz_sizeinbase (a, 2))
52 {
53 res = mpn_scan0 (a->_mp_d, b);
54 if (res != ref)
55 {
56 fprintf (stderr, "mpn_scan0 failed:\n");
57 dump ("a", a);
58 fprintf (stderr, "b: %lu\n", b);
59 fprintf (stderr, "r: %lu\n", res);
60 fprintf (stderr, "ref: %lu\n", ref);
61 abort ();
62 }
63 }
64 mini_random_scan_op (OP_SCAN1, MAXBITS, a, &b, &ref);
65 res = mpz_scan1 (a, b);
66 if (res != ref)
67 {
68 fprintf (stderr, "mpz_scan1 failed:\n");
69 dump ("a", a);
70 fprintf (stderr, "b: %lu\n", b);
71 fprintf (stderr, "r: %lu\n", res);
72 fprintf (stderr, "ref: %lu\n", ref);
73 abort ();
74 }
75 if (mpz_sgn (a) > 0 && ref != ~ (mp_bitcnt_t) 0)
76 {
77 res = mpn_scan1 (a->_mp_d, b);
78 if (res != ref)
79 {
80 fprintf (stderr, "mpn_scan1 failed:\n");
81 dump ("a", a);
82 fprintf (stderr, "b: %lu\n", b);
83 fprintf (stderr, "r: %lu\n", res);
84 fprintf (stderr, "ref: %lu\n", ref);
85 abort ();
86 }
87 }
88 }
89 mpz_clear (a);
90}