spawn: Use special invocation for <spawn.h> on OS/2 kLIBC.
[gnulib.git] / tests / test-libgmp.c
blob69deb3a60717ffc599bbea5db820a38c7d37344e
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/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <gmp.h>
22 #include <limits.h>
23 #include <string.h>
25 #include "verify.h"
27 #include "macros.h"
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);
33 #endif
35 int
36 main ()
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))
53 fprintf (stderr,
54 "gmp header version (%s) does not match gmp library version (%s).\n",
55 gmp_header_version, gmp_version);
56 exit (1);
60 #endif
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);
68 mpz_t four;
69 mpz_init (four);
70 mpz_add (four, two, two);
71 ASSERT (mpz_fits_slong_p (four));
72 ASSERT (mpz_get_si (four) == 4);
73 mpz_clear (four);
75 return 0;