1 /* Test of libgmp or its mini-gmp substitute.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
29 #ifndef MINI_GMP_LIMB_TYPE
30 /* Verify that the gmp.h header file was generated for the same
31 machine word size as we are using. */
32 verify (GMP_NUMB_BITS
== sizeof (mp_limb_t
) * CHAR_BIT
);
38 #ifndef MINI_GMP_LIMB_TYPE
39 /* Verify that the gmp.h header file and the libgmp library come from
40 the same GMP version. */
42 char gmp_header_version
[32];
43 sprintf (gmp_header_version
, "%d.%d.%d", __GNU_MP_VERSION
,
44 __GNU_MP_VERSION_MINOR
, __GNU_MP_VERSION_PATCHLEVEL
);
45 if (strcmp (gmp_version
, gmp_header_version
) != 0)
47 char gmp_header_version2
[32];
48 if (__GNU_MP_VERSION_PATCHLEVEL
> 0
49 || (sprintf (gmp_header_version2
, "%d.%d", __GNU_MP_VERSION
,
50 __GNU_MP_VERSION_MINOR
),
51 strcmp (gmp_version
, gmp_header_version2
) != 0))
54 "gmp header version (%s) does not match gmp library version (%s).\n",
55 gmp_header_version
, gmp_version
);
62 /* A simple sanity check that 2 + 2 = 4. */
63 static mp_limb_t
const twobody
[] = { 2 };
64 static mpz_t
const two
= MPZ_ROINIT_N ((mp_limb_t
*) twobody
, 1);
65 ASSERT (mpz_fits_slong_p (two
));
66 ASSERT (mpz_get_si (two
) == 2);
70 mpz_add (four
, two
, two
);
71 ASSERT (mpz_fits_slong_p (four
));
72 ASSERT (mpz_get_si (four
) == 4);