version.c revision 1.1.1.2 1 1.1 mrg /*
2 1.1 mrg * Output various information about GMP and MPFR.
3 1.1 mrg */
4 1.1 mrg
5 1.1 mrg /*
6 1.1.1.2 mrg Copyright 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
7 1.1.1.2 mrg Contributed by the AriC and Caramel projects, INRIA.
8 1.1 mrg
9 1.1 mrg This file is part of the GNU MPFR Library.
10 1.1 mrg
11 1.1 mrg The GNU MPFR Library is free software; you can redistribute it and/or modify
12 1.1 mrg it under the terms of the GNU Lesser General Public License as published by
13 1.1 mrg the Free Software Foundation; either version 3 of the License, or (at your
14 1.1 mrg option) any later version.
15 1.1 mrg
16 1.1 mrg The GNU MPFR Library is distributed in the hope that it will be useful, but
17 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 1.1 mrg License for more details.
20 1.1 mrg
21 1.1 mrg You should have received a copy of the GNU Lesser General Public License
22 1.1 mrg along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
23 1.1 mrg http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
24 1.1 mrg 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 1.1 mrg */
26 1.1 mrg
27 1.1 mrg #include <stdio.h>
28 1.1 mrg #include <limits.h>
29 1.1 mrg #include <gmp.h>
30 1.1 mrg #include <mpfr.h>
31 1.1 mrg
32 1.1 mrg /* The following failure can occur if GMP has been rebuilt with
33 1.1 mrg * a different ABI, e.g.
34 1.1 mrg * 1. GMP built with ABI=mode32.
35 1.1 mrg * 2. MPFR built against this GMP version.
36 1.1 mrg * 3. GMP rebuilt with ABI=32.
37 1.1 mrg */
38 1.1 mrg static void failure_test (void)
39 1.1 mrg {
40 1.1 mrg mpfr_t x;
41 1.1 mrg
42 1.1 mrg mpfr_init2 (x, 128);
43 1.1.1.2 mrg mpfr_set_str (x, "17", 0, MPFR_RNDN);
44 1.1 mrg if (mpfr_cmp_ui (x, 17) != 0)
45 1.1 mrg printf ("\nFailure in mpfr_set_str! Probably an unmatched ABI!\n");
46 1.1 mrg mpfr_clear (x);
47 1.1 mrg }
48 1.1 mrg
49 1.1 mrg int main (void)
50 1.1 mrg {
51 1.1 mrg unsigned long c;
52 1.1 mrg mp_limb_t t[4] = { -1, -1, -1, -1 };
53 1.1 mrg
54 1.1 mrg #if defined(__cplusplus)
55 1.1 mrg printf ("A C++ compiler is used.\n");
56 1.1 mrg #endif
57 1.1 mrg
58 1.1 mrg printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n",
59 1.1 mrg gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
60 1.1 mrg __GNU_MP_VERSION_PATCHLEVEL);
61 1.1 mrg
62 1.1 mrg printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n",
63 1.1 mrg mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR,
64 1.1 mrg MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL);
65 1.1.1.2 mrg
66 1.1.1.2 mrg #if MPFR_VERSION_MAJOR >= 3
67 1.1.1.2 mrg printf ("MPFR features: TLS = %s, decimal = %s",
68 1.1.1.2 mrg mpfr_buildopt_tls_p () ? "yes" : "no",
69 1.1.1.2 mrg mpfr_buildopt_decimal_p () ? "yes" : "no");
70 1.1.1.2 mrg # if MPFR_VERSION_MAJOR > 3 || MPFR_VERSION_MINOR >= 1
71 1.1.1.2 mrg printf (", GMP internals = %s\nMPFR tuning: %s",
72 1.1.1.2 mrg mpfr_buildopt_gmpinternals_p () ? "yes" : "no",
73 1.1.1.2 mrg mpfr_buildopt_tune_case ());
74 1.1.1.2 mrg # endif
75 1.1.1.2 mrg printf ("\n");
76 1.1.1.2 mrg #endif
77 1.1.1.2 mrg
78 1.1 mrg printf ("MPFR patches: %s\n\n", mpfr_get_patches ());
79 1.1 mrg
80 1.1 mrg #ifdef __GMP_CC
81 1.1 mrg printf ("__GMP_CC = \"%s\"\n", __GMP_CC);
82 1.1 mrg #endif
83 1.1 mrg #ifdef __GMP_CFLAGS
84 1.1 mrg printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS);
85 1.1 mrg #endif
86 1.1 mrg printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS);
87 1.1 mrg printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS);
88 1.1 mrg printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS);
89 1.1 mrg printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb);
90 1.1 mrg printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t));
91 1.1 mrg if (mp_bits_per_limb != GMP_LIMB_BITS)
92 1.1 mrg printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n");
93 1.1 mrg if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT)
94 1.1 mrg printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n");
95 1.1 mrg
96 1.1 mrg c = mpn_popcount (t, 1);
97 1.1 mrg printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c);
98 1.1 mrg if (c != GMP_LIMB_BITS)
99 1.1 mrg printf ("Warning! This is different from GMP_LIMB_BITS!\n"
100 1.1 mrg "Different ABI caused by a GMP library upgrade?\n");
101 1.1 mrg
102 1.1.1.2 mrg #if MPFR_VERSION_MAJOR >= 3
103 1.1.1.2 mrg printf ("\n");
104 1.1.1.2 mrg printf ("sizeof(mpfr_prec_t) = %d\n", (int) sizeof(mpfr_prec_t));
105 1.1.1.2 mrg printf ("sizeof(mpfr_exp_t) = %d\n", (int) sizeof(mpfr_exp_t));
106 1.1.1.2 mrg #endif
107 1.1.1.2 mrg
108 1.1 mrg failure_test ();
109 1.1 mrg
110 1.1 mrg return 0;
111 1.1 mrg }
112