blob: e230fda1fb5a26a5699189f8afe9240ac559702d [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/*
2
3Copyright 2012, 2013 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 <stdlib.h>
21#include <stdio.h>
22
23#include "testutils.h"
24
25#define MAXBITS 400
26#define COUNT 10000
27
28void
29testmain (int argc, char **argv)
30{
31 unsigned i;
32 mpz_t a, b, res, res_ui, ref;
33
34 mpz_init (a);
35 mpz_init (b);
36 mpz_init (res);
37 mpz_init (res_ui);
38 mpz_init (ref);
39
40 for (i = 0; i < COUNT; i++)
41 {
42 mini_random_op3 (OP_SUB, MAXBITS, a, b, ref);
43 mpz_sub (res, a, b);
44 if (mpz_cmp (res, ref))
45 {
46 fprintf (stderr, "mpz_sub failed:\n");
47 dump ("a", a);
48 dump ("b", b);
49 dump ("r", res);
50 dump ("ref", ref);
51 abort ();
52 }
53 if (mpz_fits_ulong_p (a)) {
54 mpz_ui_sub (res_ui, mpz_get_ui (a), b);
55 if (mpz_cmp (res_ui, ref))
56 {
57 fprintf (stderr, "mpz_ui_sub failed:\n");
58 dump ("a", a);
59 dump ("b", b);
60 dump ("r", res_ui);
61 dump ("ref", ref);
62 abort ();
63 }
64 }
65 }
66 mpz_clear (a);
67 mpz_clear (b);
68 mpz_clear (res);
69 mpz_clear (res_ui);
70 mpz_clear (ref);
71}